Problem with delete and left join
I try to delete all non-matching records from two tables. My tables, t1 and t2, look like this:
t1:
+----+-------+
| id | item |
+----+-------+
| 1 | bike |
| 2 | car |
| 3 | house |
+----+-------+
t2:
+----+---------+
| id | name |
+----+---------+
| 1 | Andy |
| 2 | Ben |
+----+---------+
If i run the following SQL:
SELECT * FROM t1 LEFT JOIN t2 ON t1.id = t2.id WHERE t2.id IS NULL
I get the non maching record displayed:
+----+-------+------+------+
| id | item | id | name |
+----+-------+------+------+
| 1 | house | NULL | NULL |
+----+-------+------+------+
Witch is nice. The problem is if I trying to delete the non-mathing post with this SQL:
DELETE t1 FROM t1 LEFT JOIN t2 ON t1.id = t2.id WHERE t2.id IS NULL;
I got this message:
ERROR 1064: You have an error in your SQL syntax near 't1 FROM t1 LEFT JOIN t2 ON t1.id = t2.id WHERE t2.id IS NULL' at line 1
Im not able to solve this problem, so I hope anybody can help me.
Im running MySQL server ver 3.23.58-1.9 on RH Linux v9
Subject
Written By
Posted
Problem with delete and left join
August 26, 2004 09:34AM
Sorry, you can't reply to this topic. It has been closed.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.