WebmasterA
Programmer
Hello,
I have a sort question.
I have two table: topics and messages for those topics.
Each topic can have multiple messages.
I need to select the topic name and the last message posted.
topics table
topic_id (int)
topic_header (varchar 100)
topic_text (text)
messages table
mesage_id (int)
topic_id (int)
message_text (text)
message_date (datetime)
Here is my select statement
select a.topic_id, a.topic_header, max(messsages.message_date)
from topics a
left outer join messages(a.topic_id=messages.topic_id)
order by messages.message_date
Unfortunately order by in this case sorts ALL the messages. I need to sort only the selected MAX ones.
Does anyone have an idea how to do it.
Thank you.
- Andrey
P.S. please let me know if you have any questions about my problem
I have a sort question.
I have two table: topics and messages for those topics.
Each topic can have multiple messages.
I need to select the topic name and the last message posted.
topics table
topic_id (int)
topic_header (varchar 100)
topic_text (text)
messages table
mesage_id (int)
topic_id (int)
message_text (text)
message_date (datetime)
Here is my select statement
select a.topic_id, a.topic_header, max(messsages.message_date)
from topics a
left outer join messages(a.topic_id=messages.topic_id)
order by messages.message_date
Unfortunately order by in this case sorts ALL the messages. I need to sort only the selected MAX ones.
Does anyone have an idea how to do it.
Thank you.
- Andrey
P.S. please let me know if you have any questions about my problem