Page is a not externally linkable
- Code, Content, and Presentation
-- PHP Server Side Scripting
---- MySQL remove rows with value that exists in rows with certain value


timster - 11:28 pm on Mar 5, 2011 (gmt 0)


Welcome to webmasterworld.

You can find the similar rows inside the same table with a self join. But I don’t think you will be able to delete the rows from the same table in the same query.

The solution is to create a duplicate table to select from. Then select the data from the duplicate table, and then to delete the data in the first table.

Here is example code. Please test it, and when you are sure it does what you want, replace the “select *” with “delete”. Of course, you’ll have to replace the names of the tables as well.


select *
from test
where id in (

select t1.id
from test_copy t1
join
test_copy t2 on
t1.value = t2.value
where t1.cid = 1
and t2.cid = 3

);


Thread source:: http://www.webmasterworld.com/php/4276544.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com