简体   繁体   中英

order by and limit condition in mysql

$sqlsl = "select * from newmessage where sendto='".$userid."' order by inboxid limit 10";

Pease help me,

Above table retrieve first 10 rows in my badabase in ASC order. My database contain 100 recordes. I want only first 10 recordes in DESCing order

Please try

"$sqlsl = "select * from newmessage where sendto='".$userid."'
order by inboxid  DESC limit 10";

See this page in the MySQL documentation.

$sqlsl = "select * from newmessage where sendto='".$userid."' order by inboxid DESC limit 10";

To get the records in descending order you should add the DESC keyword to the order by clause:

$sqlsl = "select * from newmessage 
where sendto='".$userid."' 
order by inboxid desc 
limit 10";

Use this

select * from (select * from newmessage where sendto='".$userid."' order by inboxid limit 10) as message_id order by message_id desc

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM