Yackem Posted June 13, 2008 Share Posted June 13, 2008 Greetings. I own a message board and have recently added new Topic Types outside of the regular normal, stickies, global...etc. Currently the sql looks as follows: SELECT t.topic_type FROM phpbb_topics t WHERE t.forum_id = 2 AND t.topic_type IN (0,1,2,3,4,5,6,7,8,9) ORDER BY t.topic_type DESC, t.topic_last_post_time DESC The output shows topic_type 9 9 9 8 8 8 . . . I would like for the entries that have t.topic_type = 1 always be listed first and ordered by t.topic_last_post_time ASC. And then the remaining entries just ordered by t.topic_last_post_time DESC. So an output like this. topic_type 1 1 1 1 1 1 4 5 3 . . Can anyone point me in the right direction as to get this accomplished? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/110007-separating-items-and-ordering-them/ Share on other sites More sharing options...
keeB Posted June 13, 2008 Share Posted June 13, 2008 Gonna have to use 2 queries. I'd do it inside of the same transaction. Quote Link to comment https://forums.phpfreaks.com/topic/110007-separating-items-and-ordering-them/#findComment-564515 Share on other sites More sharing options...
Yackem Posted June 13, 2008 Author Share Posted June 13, 2008 I don't know enough about nested queries so I went ahead and made two separate queries. The end result is what I needed. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/110007-separating-items-and-ordering-them/#findComment-564548 Share on other sites More sharing options...
fenway Posted June 13, 2008 Share Posted June 13, 2008 You need to use multiple order by clauses... do you still care? Quote Link to comment https://forums.phpfreaks.com/topic/110007-separating-items-and-ordering-them/#findComment-564773 Share on other sites More sharing options...
keeB Posted June 13, 2008 Share Posted June 13, 2008 You need to use multiple order by clauses... do you still care? You can do multiple? Cool. edit: If he doesn't I do Quote Link to comment https://forums.phpfreaks.com/topic/110007-separating-items-and-ordering-them/#findComment-564824 Share on other sites More sharing options...
fenway Posted June 13, 2008 Share Posted June 13, 2008 Well, not multiple "ORDER BY"s, just separate groupings, is what I meant to say. For example, ORDER BY IF( t.topic_type = 1, 0, 1 ) ASC will always put topic_type 1 first. Then it gets more complicated... Quote Link to comment https://forums.phpfreaks.com/topic/110007-separating-items-and-ordering-them/#findComment-564903 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.