欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

基于mysql中delete的语法别名问题

程序员文章站 2022-03-17 12:13:38
目录mysql delete的语法别名问题首先确认,mysql中的delete语句是支持别名的;在自己书写delete语法时候,语句如下:delete from tablea a where a.c_...

mysql delete的语法别名问题

首先确认,mysql中的delete语句是支持别名的;

在自己书写delete语法时候,语句如下:

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的语法有些特殊,如下:

delete   a   from tablea  a  where a.c_pk_id = '123'

成功删除!!!

比较之后可知道,delete语句在用别名的时候要多写一个别名在delete后边

mysql delete 语句中使用别名 alias

语法:

delete <alias> from <table> <alias> where <alias>.<field>...

别名必需在 delete之后出一次。

多表间删除语法:

delete t1, t2 from t1 inner join t2 inner join t3
where t1.id=t2.id and t2.id=t3.id;

or:

delete from t1, t2 using t1 inner join t2 inner join t3
where t1.id=t2.id and t2.id=t3.id;

left join:

delete t1 from t1 left join t2 on t1.id=t2.id where t2.id is null;

以上为个人经验,希望能给大家一个参考,也希望大家多多支持。