Home » SQL & PL/SQL » SQL & PL/SQL » Separating items and then ordering (MYSQL)
Separating items and then ordering [message #326863] Thu, 12 June 2008 21:47 Go to next message
Yackem
Messages: 2
Registered: June 2008
Junior Member
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.
Re: Separating items and then ordering [message #326864 is a reply to message #326863] Thu, 12 June 2008 22:10 Go to previous messageGo to next message
ebrian
Messages: 2794
Registered: April 2006
Senior Member
SQL> select * from test_num;

        A1
----------
         4
         1
         6
         1
         5
         7
         1
         8
         9
         3
         1

11 rows selected.

SQL> select * from test_num
  2  order by decode(a1, 1, 1);

        A1
----------
         1
         1
         1
         1
         9
         3
         8
         5
         6
         4
         7

11 rows selected.


By the way, this is an Oracle forum and not a MySQL forum. I don't think all SQL solutions convey to MySQL.
Re: Separating items and then ordering [message #326869 is a reply to message #326863] Thu, 12 June 2008 22:21 Go to previous message
Yackem
Messages: 2
Registered: June 2008
Junior Member
Embarassed dont I feel dumb.

thanks!
Previous Topic: Suggestions and work around required urgently
Next Topic: execute a sql file within sql?
Goto Forum:
  


Current Time: Sun Dec 11 02:10:17 CST 2016

Total time taken to generate the page: 0.06120 seconds