Jump to content

adding WHERE to a query


abitshort

Recommended Posts

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;

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.