sql - MySQL Advanced ORDER BY Clause for message reply system -
i have page users can post message. each message posted can make reply shown right after original message.
see mysql table :
id | user_id | message | date | second_reply_id 1 48 hi post message 2013-08-08 13:00:00 0 2 20 hi post message 2013-08-08 14:00:00 0 3 17 , reply message 1 2013-08-08 15:00:00 1 4 8 , reply message 2 2013-08-08 16:00:00 2 5 10 hi post new message 2013-08-08 17:00:00 0 6 7 reply reply id 3 2013-08-08 18:00:00 1 is there way order result of select query :
id | user_id | message | date | second_reply_id 5 10 hi post new message 2013-08-08 17:00:00 0 2 20 hi post message 2013-08-08 14:00:00 0 4 8 , reply message 2 2013-08-08 16:00:00 2 1 48 hi post message 2013-08-08 13:00:00 0 3 17 , reply message 1 2013-08-08 15:00:00 1 6 7 reply reply id 3 2013-08-08 18:00:00 1 thank you
try (unfortunately not work if can reply reply):
select id , user_id, message, date, second_reply_id my_table order second_reply_id, if( second_reply_id = 0, id, second_reply_id ) update: order replies oldest newest use :
order if(second_offer_id =0, id, second_offer_id ) asc , if(second_offer_id =0, 'xxxx', date ) desc
Comments
Post a Comment