Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Ordering 2 tables query

Status
Not open for further replies.

5ilver5aracen

Programmer
Oct 24, 2004
32
0
0
GB
Hi, I have 2 tables. TableA contains course details and TableB contains the dates that these courses are on. There can be many dates for each course. I have tried quite a few sql statements to try and produce a list of courses that are in date order. The courses need to be ordered by their earliest date and the courses should only appear once in the list. It sounds simple but I cant seem to work it out. It would work if a GROUP BY could be used with a ORDER BY! Many thanks in advance. SilverSaracen
 
Do you mean this?

Code:
SELECT a.coursename, MIN(b.coursedate)
FROM tablea a JOIN tableb b ON a.courseid = b.courseid
GROUP BY a.coursename
ORDER BY MIN(b.coursedate)

--James
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top