Skip to main content
2 of 3
added 5 characters in body
RolandoMySQLDBA
  • 184.3k
  • 33
  • 323
  • 531

Problem with MySQL subquery

Why does 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