mysql delete的语法别名问题
首先确认,mysql中的delete语句是支持别名的;
在自己书写delete语法时候,语句如下:
1
|
delete from tableA a where a.c_pk_id = '123' |
但是会报一个别名使用错误,如下:
[Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'q
WHERE
q.C_PLY_NO = '1100107000404000220150000001'
AND q.N_EDR_PRJ_NO = '1'' at line 3
通过查询资料得知,mysql的delete的语法有些特殊,如下:
1
|
delete a from tableA a where a.c_pk_id = '123' |
成功删除!!!
比较之后可知道,delete语句在用别名的时候要多写一个别名在delete后边
mysql delete 语句中使用别名 alias
语法:
1
|
delete <alias> from < table > <alias> where <alias>.<field>... |
别名必需在 delete之后出一次。
多表间删除语法:
1
2
|
DELETE t1, t2 FROM t1 INNER JOIN t2 INNER JOIN t3 WHERE t1.id=t2.id AND t2.id=t3.id; |
Or:
1
2
|
DELETE FROM t1, t2 USING t1 INNER JOIN t2 INNER JOIN t3 WHERE t1.id=t2.id AND t2.id=t3.id; |
LEFT JOIN:
1
|
DELETE t1 FROM t1 LEFT JOIN t2 ON t1.id=t2.id WHERE t2.id IS NULL ; |
以上为个人经验,希望能给大家一个参考,也希望大家多多支持服务器之家。
原文链接:https://blog.csdn.net/qq_16736531/article/details/51136424