razvypp Posted April 8, 2010 Share Posted April 8, 2010 can any one tell me why i get error ? $s = "Select * from chat_global order by id ASC"; (works) but as soon as i add 'Top 3' ,like below $s = "Select Top 3 * from chat_global order by id ASC"; 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 '3 * from chat_global order by id ASC' at line 1 Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in Q:\www\chat.php on line 24 Link to comment https://forums.phpfreaks.com/topic/197994-mysql-select-top-error/ Share on other sites More sharing options...
Deoctor Posted April 8, 2010 Share Posted April 8, 2010 i dont think top will work under mysql. it works in the sql server.. try some thing like this SELECT DISTINCT( `cloumnA` ), COUNT( `columnA` ) FROM `tablename` GROUP BY 1 ORDER BY 2 DESC LIMIT 0,10; Link to comment https://forums.phpfreaks.com/topic/197994-mysql-select-top-error/#findComment-1038939 Share on other sites More sharing options...
razvypp Posted April 8, 2010 Author Share Posted April 8, 2010 but i need more fields to be selected not only one , and i want it for a chat , so the last entry should be the last printed , so order should be ASC not DESC , any one have a solution ? Link to comment https://forums.phpfreaks.com/topic/197994-mysql-select-top-error/#findComment-1038956 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.