I’m a little new to SQL and have come across the following problem.
I have a table with company details on it which is joined to a contact table by an enqID.
Within the contact table, there are 4 different types of contacts which may or may not have an entry. These are differentiated by a ctcTypID (1 – 4)
I would like to produce a query that has all of the company records on it plus a contact name for each of the 4 different types of contact, all on one row.
I thought I could do this by using subqueries for each of the different contacts but I can’t seem to get it to work as I don’t know how to write a subquery select clause that references it’s parent select clause (if you see what I mean!)
Is this even possible? As I’ve mentioned, I’m pretty new to SQL so please try not to mock too much!
Thanks,
Steve
Something like (assuming you’re using SQL Server 2005 and up – unfortunately, you didn’t mention that in your original post):
You need to use LEFT OUTER JOINs since there might not be a match, and by doing this, your query will not be awfully fast in terms of performance – but it should hopefully work.
Marc