Rajesh
Rajesh

Reputation: 163

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

Upvotes: 1

Views: 15418

Answers (4)

Pradeep Singh
Pradeep Singh

Reputation: 3634

Use this

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

Upvotes: 0

Bas Danen
Bas Danen

Reputation: 311

Please try

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

See this page in the MySQL documentation.

Upvotes: 3

subosito
subosito

Reputation: 3470

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

Upvotes: 5

codaddict
codaddict

Reputation: 454950

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";

Upvotes: 2

Related Questions