Jump to content

Separating Items and Ordering Them


Yackem

Recommended Posts

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

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.