G
G
gloribus2016-08-07 00:05:06
PHP
gloribus, 2016-08-07 00:05:06

How to take a random record from a table, but so that the record ID of this record does not occur in another table?

How to take a random record from a table, but so that the record ID of this record does not occur in another table?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
WebDev, 2016-08-07
@gloribus

SELECT * FROM `table1` WHERE `id` NOT IN(
    SELECT `id` FROM `table2`
) ORDER BY RAND() LIMIT 1

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question