...

View Full Version : Please help with deleting "every other row" in mysql table



eapro
09-04-2009, 10:45 AM
What I'm trying to do is simple; I need to delete every other row in a mysql table.
skip row, delete, skip row, delete, skip row, delete ...

For example this table:

id | name
---------------
1 | John
2 | Bob
3 | Mary
4 | Alex
5 | Tom
6 | Pat


After delete, becomes this:

id | name
---------------
1 | John
3 | Mary
5 | Tom


Any ideas?

Fumigator
09-04-2009, 03:25 PM
Assuming your "id" column is a continuous sequence of numbers, check the modulus of the id divided by 2 and delete when it's 0.



DELETE FROM table1
WHERE ID % 2 = 0

eapro
09-04-2009, 06:34 PM
That worked perfectly, thanks! :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum