我将从 2 个表中删除数据。我会这样做:
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
但这会返回 SQL 语法错误。如何通过 SQL AS 语句解决此问题?就像下面的例子一样。
SELECT first_name.last_name AS name WHERE name="John Doe"
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
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
您的原始语句也是正确的如果您添加表的别名,一个示例SQL Fiddle