Kentaurs
Kentaurs

Reputation: 11

Mysql ASC function ORDER only first ID's

I have this line:

$query = mysql_query("SELECT * FROM livechat WHERE type='public' ORDER BY id ASC LIMIT 15") ;

And this is for chat, however ASC takes only first ID comments, so it shows only 15 old comments (id1, id2 and so on). If I use DESC instead of ASC, it shows new comments, but in a bad way - newest at the top, since this is a chat, newest comments must be at the bottom.

Upvotes: 1

Views: 48

Answers (2)

igimak
igimak

Reputation: 16

try like this:

$query = mysql_query("SELECT *
    FROM (
    SELECT *
    FROM livechat 
    WHERE type='public'
    ORDER BY id DESC LIMIT 15
) t
order by t.id")  ;

Upvotes: -1

bill
bill

Reputation: 1656

Try creating a temporary table that contains the last 15 results, and then ordering from that table.

select * from (
    select * from livechat where type='public' order by id desc limit 15
) tmp order by tmp.id asc

Upvotes: 2

Related Questions