Showing posts with label status. Show all posts
Showing posts with label status. Show all posts

Friday, March 30, 2012

Order by string...?

hey everyone...

at the moment, I have 3 status types of items in my db... approved, pending & draft...

what im wanting to know is...

can i do a ORDER BY [status is Draft] so that any items where status (VARCHAR) is draft is at the top of the list..

I can't do alphabetical order...because d is inbetween A & P...

CheersORDER
BY CASE WHEN status = 'draft'
THEN 1
ELSE 937 END
, status
, item_name

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