Hi
table contact1: obviously contact information
table contsupp: a catch all for a one to many per contact
we keep course detail in contsupp; each course a contact has taken is a row in this table - the field names are not descriptive.
I want to list only one course per contact, doesn't matter which, the first one it encounters is fine.
this code works fine except that it gives me all the courses that a contact has taken, not just the first.
when I run just the select in brackets, it gives me only one record.
also, when I put accountno = contsupp.accountno in where clause in the sub query, I get no rows returned.
when I move the where clause "contsupp.contact = 'course name' and contsupp.contsupref like 'trg%'" in the sub-query where clause - which is where I thought it ought to be because those fields are in contsupp - it gives me every contsupp record for a contact, not just courses.
I don't understand what I'm doing wrong.
Code:
SELECT c1.accountno, c1.contact, contsupp.contact, contsupp.contsupref, contsupp.country, contsupp.accountno
FROM contact1 c1
JOIN contsupp
ON contsupp.accountno =
(
SELECT TOP 1 accountno
FROM contsupp
WHERE accountno = c1.accountno
)
where contsupp.contact = 'course name' and contsupp.contsupref like 'trg%'
order by c1.contact
thanks in advance for your help.
kim