MySQL Forums
Forum List  »  Newbie

UNION and ORDER BY problem
Posted by: David Nash
Date: March 14, 2011 01:51PM

Hi everyone - I wonder if someone could help me? I have a comment section on my website and I want to display the most popular comment first and then the rest of the comments from newest to oldest (Like Youtube). Here is my code for the query:

SELECT * FROM comments ORDER BY rating DESC LIMIT 1
UNION
SELECT * FROM comments ORDER BY id DESC


It works for the Top comment but the rest are not being sorted newest to oldest. If I just do:

SELECT * FROM comments ORDER BY id DESC

it sorts them fine so I guess it's something to do with the UNION?

Please help me!

Kind Regards



Edited 2 time(s). Last edit at 03/14/2011 02:26PM by David Nash.

Options: ReplyQuote


Subject
Written By
Posted
UNION and ORDER BY problem
March 14, 2011 01:51PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.