Hi all,
I need some help building a query that I need, but I can't get it to work.
I have a customers table and a customers contact details table.
Its a one to many relation.
CustomerID - FK
MediaTypeID - FK (its phone or email)
LabelID - FK (its a label, like invoice address or mobile address)
MediaAdress (the actual value)
I want to get a list with all CustomerID
Then only the email addresses
Then only the LabelID is 7
But if the customer doesnt have a labelid 7, then I just want the first one or a Null if he doesnt have any mail address.
Select CustomerID, MediaAddress
From tblContactDetails
Where MediaTypeID = 2
And LabelID = 7
But that only shows the ones with LabelID 7.
If there is no 7 I want the first one or a null.
Do you have any idea on how to achieve this?
I need some help building a query that I need, but I can't get it to work.
I have a customers table and a customers contact details table.
Its a one to many relation.
CustomerID - FK
MediaTypeID - FK (its phone or email)
LabelID - FK (its a label, like invoice address or mobile address)
MediaAdress (the actual value)
I want to get a list with all CustomerID
Then only the email addresses
Then only the LabelID is 7
But if the customer doesnt have a labelid 7, then I just want the first one or a Null if he doesnt have any mail address.
Select CustomerID, MediaAddress
From tblContactDetails
Where MediaTypeID = 2
And LabelID = 7
But that only shows the ones with LabelID 7.
If there is no 7 I want the first one or a null.
Do you have any idea on how to achieve this?