Jump to content

order by problem


psychohagis

Recommended Posts

ive got this expression to work:

[code]$messages = @mysql_query(
  'SELECT mid, from1, subject, message, received, read1, username
FROM messages, users
WHERE to1 ='.$userid.' AND from1 = users.id LIMIT 0 , 30 ');[/code]

But I know want to add [b]ORDER BY mid DESC[/b]. but when I do it complains as follows:

[quote]Error performing query: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'ORDER BY mid DESC' at line 4[/quote]
Link to comment
https://forums.phpfreaks.com/topic/33196-order-by-problem/
Share on other sites

The ORDER BY clause must come before the LIMIT clause.  More precisely:

[code]
$messages = @mysql_query(
  'SELECT mid, from1, subject, message, received, read1, username
FROM messages, users
WHERE to1 ='.$userid.' AND from1 = users.id ORDER BY mid DESC LIMIT 0 , 30 ');
[/code]
Will work, while
[code]
$messages = @mysql_query(
  'SELECT mid, from1, subject, message, received, read1, username
FROM messages, users
WHERE to1 ='.$userid.' AND from1 = users.id LIMIT 0 , 30 ORDER BY mid DESC ');
[/code]
will not.

Best,

Patrick
Link to comment
https://forums.phpfreaks.com/topic/33196-order-by-problem/#findComment-155048
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.