Hello, I'm getting a syntax error in this query line. SELECT `title`, `link`, `image` FROM `advertisements` WHERE `live` = \'yes\' RAND()<(SELECT ((1/COUNT(*))*10) FROM `advertisements`) ORDER BY RAND() LIMIT 4; Code (markup): The syntax error is 'You have a syntax error new RAND.' Not sure if there should be an AND in there, or something else. It's selected 4 random rows. Thanks, Jeremy.
There is one mistake in this line, to resolve this issue firstly use this sintex SELECT `title`, `link`, `image` FROM `advertisements` WHERE `live` = '\'yes\' RAND()<(SELECT ((1/COUNT(*))*10) FROM `advertisements`) ORDER BY RAND() LIMIT 4;
I don't get what you are trying to do with the rand comparison but I was able to get this running against a table in my database SELECT `id`, `title`, RAND() AS randresult FROM `contents` WHERE `contents`.`active` = 1 HAVING randresult < (SELECT ((1/COUNT(*))*10) FROM `contents`) ORDER BY `randresult` LIMIT 4 Code (markup): You need to only call rand() once otherwise you'll get completely different results and the order by clause will look like it's broken
Have been thinking about this Is the subquery to limit the number of rows returned? If so, then you can just leave it out and let the limit 4 do the job