abitshort Posted December 10, 2009 Share Posted December 10, 2009 SELECT * FROM tablename AS t1 INNER JOIN ( SELECT ROUND(RAND() * (SELECT MAX(id) FROM tablename)) AS id ) AS t2 ON t1.id >= t2.id ORDER BY t1.id ASC LIMIT 1; ------------- Could anyone please help me to add WHERE live = '1' to the above query? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/184615-adding-where-to-a-query/ Share on other sites More sharing options...
Mchl Posted December 10, 2009 Share Posted December 10, 2009 SELECT * FROM tablename AS t1 INNER JOIN ( SELECT ROUND(RAND() * (SELECT MAX(id) FROM tablename)) AS id ) AS t2 ON t1.id >= t2.id WHERE live = '1' ORDER BY t1.id ASC LIMIT 1; or SELECT * FROM tablename AS t1 INNER JOIN ( SELECT ROUND(RAND() * (SELECT MAX(id) FROM tablename WHERE live = '1')) AS id ) AS t2 ON t1.id >= t2.id ORDER BY t1.id ASC LIMIT 1; Quote Link to comment https://forums.phpfreaks.com/topic/184615-adding-where-to-a-query/#findComment-974594 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.