Gossamer Forum
Home : General : Databases and SQL :

Help pls: SELECT... ORDER BY

Quote Reply
Help pls: SELECT... ORDER BY
Here's my SQL statement:

SELECT T.TOPIC_ID, T.SUBJECT, E.EVENT_DATE
FROM TOPICS T, EVENTS E
WHERE T.TOPIC_ID = E.TOPIC_ID
ORDER BY E.TOPIC_ID Desc, E.EVENT_DATE

It kind of works but instead of sorting by TOPIC_ID, I want to sort by the earliest event_date in each topic, but I still want all the records with the same TOPIC_ID to be contiguous. So my data should look like this:

TOPIC_ID, EVENT_DATE
4, 5/12/2003
4, 5/15/2003
4, 5/20/2003
4, 5/29/2003
3, 5/13/2003
3, 5/14/2003
1, 5/15/2003
1, 5/18/2003
1, 5/19/2003
2, 5/16/2003
2, 5/19/2003

The topic with the earliest EVENT_DATE are listed first, followed by records with the same TOPIC_ID arranged by date. How do I do this?
Quote Reply
Re: [awesomekenny] Help pls: SELECT... ORDER BY In reply to
Use the GROUP BY function...
========================================
Buh Bye!

Cheers,
Me