Wednesday, March 28, 2012

order by not working properly

Hello, i have something like this, i want the annoucements (status = 0) to be on top, then topics with (status = 1) below, then the rest of the topics.

So i tried:

SELECT

forum_topics.id, forum_topics.status, forum_topics.usernameAS starter, forum_topics.subject, forum_topics.closed, forum_topics.answerpostid, forum_topics.views, forum_topics.answers, forum_topics.lastanswer, forum_topics.lastanswerid, forum_topics.createdAS started, forum_answer.username, forum_answer.answer, forum_answer.createdFROM forum_topicsLEFTOUTERJOIN forum_answerON forum_answer.id= forum_topics.lastansweridWHERE(boardid= @.IDOR boardid= 0)ORDERBY(status)ASC,(created)ASC

Problem is that they are not sorted diffrently, when i change the (created) ASC to (created) DESC i get the same result and the rows are not sorted, they only get sorted by status so i have status=0 at the top, then status=1 then the rest. How do i get them to be sorted first by status ASC then by created ASC/DESC?

Patrick

try this:

ORDERBY forum_topics.statusASC, forum_answer.createdASC

No comments:

Post a Comment