Skip to main content
1 of 3
tomas.lang
  • 253
  • 2
  • 5

Problem with MySQL subquery

Why this query DELETE FROM test WHERE id=(SELECT id FROM (SELECT * FROM test) temp ORDER BY RAND() LIMIT 1); sometimes delete 1 row, sometimes 2 rows and sometimes nothing?

If I write it in this form: SET @var = (SELECT id FROM (SELECT * FROM test) temp ORDER BY RAND() LIMIT 1); DELETE FROM test WHERE id=@var;, then it work correctly - is problem in subquery?

tomas.lang
  • 253
  • 2
  • 5