Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deleting random rows from a table without knowing anything about the table ids

I'm having a problem in mysql. I want to delete 20 rows from a table containing 100+ records.

I do not know the id's of the rows, any special identification of the rows to be deleted. I want to just delete the any random rows from my table.

Please help me... i am new to this condition.

like image 592
Cool Sporty Avatar asked Jan 17 '23 03:01

Cool Sporty


1 Answers

You can do:

DELETE FROM tbl
ORDER BY RAND()
LIMIT 20

See MySQL DELETE syntax

like image 88
Zane Bien Avatar answered Jan 18 '23 22:01

Zane Bien