tags:

views:

68

answers:

2

is it posssible to execute a delete query statement that joins the same table, i've tried various joins (inner, left) but no luck mysql returns error

example of what i need:

DELETE `a` FROM `t1` AS `a`
INNER JOIN `t1` AS `b` USING `some_field_b`
WHERE 
    `a`.`some_field_a` = 'value_x' AND 
    `b`.`some_field_a` = 'value_y'
A: 

Although the manual seems to suggest the INNER JOIN syntax should work in a DELETE, I know that this alternative with the join clause moved to the where condition would work....

DELETE  a.* FROM t1 AS a, t1 as b 
WHERE 
    a.some_field_b=b.some_field_b AND
    a.some_field_a = value_x AND 
    b.some_field_a = value_y

Edit: I just tried this, which worked for me:

DELETE a FROM t1 AS a 
INNER JOIN t1 as b USING(some_field_b) 
WHERE 
    a.some_field_a = value_x AND 
    b.some_field_a = value_y
Paul Dixon
A: 

yep it worked fine now, i used incorrect field name in where clause at my previous test queries ;)

norewind