Raymond van Os
Raymond van Os

Reputation: 191

SQL DELETE from two tables in the same statement

I will delete data from 2 tables. I will do it as follow:

 DELETE FROM dc_mail_users u, dc_mail_user_data d WHERE u.i_id_pk = 3 AND d.i_id_ut = u.i_id_pk

But this will return a SQL syntax error. How can I fix this whit the SQL AS statement? Just like the example below.

SELECT first_name.last_name AS name WHERE name="John Doe"

Upvotes: 2

Views: 4423

Answers (3)

wchiquito
wchiquito

Reputation: 16551

Your original statement would also be correct If you add the alias of the tables, an example SQL Fiddle

Upvotes: 2

user1191247
user1191247

Reputation: 12998

DELETE u, d
FROM dc_mail_users u
INNER JOIN dc_mail_user_data d
    ON d.i_id_ut = u.i_id_pk
WHERE u.i_id_pk = 3

Upvotes: 3

purplesoft
purplesoft

Reputation: 526

delete u, d
FROM dc_mail_users u
join dc_mail_user_data d
on d.i_id_ut = u.i_id_pk
and u.i_id_pk = 3 

Upvotes: 2

Related Questions