HDRebel88 Posted June 1, 2014 Share Posted June 1, 2014 I need some help working out this MySQL query: I need it to pull a random quote, that hasn't been used before (that's the 'checked' part of the query), and it needs to find it based on a specific category. I am using this alongside PHP with MySQLI Prepared method. SELECT `id`, `word`, `def` FROM `dictionary` AS `r1` JOIN (SELECT (RAND() * (SELECT MAX(`id`) FROM `dictionary`)) AS `id`) AS `r2` WHERE `r1`.`id` >= `r2`.`id` AND `category`=? AND `checked`=0 ORDER BY `r1`.`id` ASC LIMIT 1 This query yields an error stating that the id column is ambiguous. Link to comment https://forums.phpfreaks.com/topic/288921-get-random-quote/ Share on other sites More sharing options...
HDRebel88 Posted June 2, 2014 Author Share Posted June 2, 2014 Solved... Needed to add `r1` to the beginning of each SELECTed column. Link to comment https://forums.phpfreaks.com/topic/288921-get-random-quote/#findComment-1481588 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.