Thank you both for your very prompt replies.
[bold]Borislov:[/bold] your query does indeed work, however, when I add, after the line RowN = 1,
Code:
inner join maincourses mc on mc.code = contsupp.contsupref and mc.ucrstart > '01/01/2010' and mc.code like 'trg%'
to retrieve on the courses since the beginning of 2010, I get all of the courses for each person again.
[bold]Frederico:[/bold]
first, a question - or two: if when the subquery is run as a standalone query it works correctly and returns only the first course record for an account number, then why doesn't it work properly as a subquery.
yes, there are multiple records on contsupp with the same accountno, the link between contact1 and the contact detail records in contsupp; a contact may take several courses distinguished by only the course code. isn't that the way a many-to-one relationship works?
I'm not sure how much data you would like , but I'm listing all of the records on the contsupp (detail) table for one contact only; other contacts would have similar records with the exception of the number of courses. I don't know how to get the columns to line up, I did insert the [tab] [/tab] tags, but perhjaps I don't understand how that works, but the columns are:
account number
contsupp.contact - detail type, i.e. a row with a detail type of 'Course Name' contains data for a course taken by the contact
contsupp.rectype - always 'P' for course detail records & some others as well
contsupref - detail data dependent on detail type
contsup.title - additional detail data (course date)
what I want to return is only the first course detail record - the one I've highlighted
[tab]
A7121242416&1*VN!Ada A1092533626(3T%.)Joh O 1000001000 Ada Wong-Ferenci NULL
[highlight #FF99FF]
A7121242416&1*VN!Ada Course Name P TRG 1326 Nov 26-27
[/highlight]
A7121242416&1*VN!Ada Course Name P TRG 1329 Nov 28-29
A7121242416&1*VN!Ada Course Name P TRG 1318 May 9-11
A7121242416&1*VN!Ada Course Name P TRG 1312 May 7-8
A7121242416&1*VN!Ada Course Name P TRG 1378 May 14-15
A7121242416&1*VN!Ada Course Name P TRG 1322 June 24-25
A7121242416&1*VN!Ada Course Name P TRG1516 20-Jul
A7121242416&1*VN!Ada Course Name P TRG1654 13-Nov
A7121242416&1*VN!Ada Course Name P TRG1515
A7121242416&1*VN!Ada Course Name P TRG1746 19-Aug
A7121242416&1*VN!Ada Course Name P 22-Jul
A7121242416&1*VN!Ada Course Name P TRG1974 15-Apr
A7121242416&1*VN!Ada E-mail Address P ada.wongferenci@goldenboyfoods.com
A7121242416&1*VN!Ada E-mail Address P a.wongferenci@goldenboyfoods.com
A7121242416&1*VN!Ada E-mail Address P ada.wongferenci@hotmail.com
A7121242416&1*VN!Ada WEB SITE P
[/tab]
I was going to attach a Word document showing the table definitions but I couldn't figure out how to do it. are you ok without it or should I email it?
I apologize, but I don't understand when you say:
"for the "top 1 xxx" to work as you wish, the xxx needs to be a unique field or at least one that if you join with other fields on contact1 makes it unique"
shouldn't the sub-query just create a list as if it was a regular query returning the records that match the criteria and then just return the top one? as I say, it works when the sub-query runs as a standalone.
thanks so much
kim