Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does my SQL query fail?

I'm using this to retrieve information from a database, the query always brings errors

This is my query:

SELECT * FROM users ORDER BY RAND() LIMIT '10'

It always brings up errors on either the ORDER BY RAND() or the LIMIT '10'.

Any reason why this is happening? Also is there any solutions to this?

like image 533
John Smith Avatar asked Dec 13 '10 20:12

John Smith


2 Answers

Limit should be integer? 10 instead '10'.

like image 91
IProblemFactory Avatar answered Sep 26 '22 01:09

IProblemFactory


SELECT *
FROM affiliate
ORDER BY RAND()
LIMIT 10 

Note there are no quotes around 10

like image 26
Thomas Hunter II Avatar answered Sep 25 '22 01:09

Thomas Hunter II