psychohagis Posted January 7, 2007 Share Posted January 7, 2007 ive got this expression to work:[code]$messages = @mysql_query( 'SELECT mid, from1, subject, message, received, read1, usernameFROM messages, usersWHERE 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 More sharing options...
utexas_pjm Posted January 7, 2007 Share Posted January 7, 2007 The ORDER BY clause must come before the LIMIT clause. More precisely:[code]$messages = @mysql_query( 'SELECT mid, from1, subject, message, received, read1, usernameFROM messages, usersWHERE 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, usernameFROM messages, usersWHERE 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.