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. Quote Link to comment Share on other sites More sharing options...
Solution HDRebel88 Posted June 2, 2014 Author Solution Share Posted June 2, 2014 Solved... Needed to add `r1` to the beginning of each SELECTed column. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.