多表联合删除的写法
用户表 tbl_user
公司表 tbl_company
电话表 tbl_user_mobile
查出公司Id=1231公司的所有的员工手机,我们很方便的写出sql语句
select * from tbl_user,, tbl_user_mobilewhere tbl_user.companyId =’1231’ and tbl_user_mobile.userId= tbl_user.userId
但是想要删除公司Id=1231公司的所有的员工手机
delete from tbl_user,, tbl_user_mobile where tbl_user.companyId =’1231’ and tbl_user_mobile.userId= tbl_user.userId 这样会出错,因为sql语句逻辑问题,因为不知道要在哪个表里面删除,所以改成这样delete tbl_user from tbl_user, tbl_user_mobile where tbl_user.companyId =’1231’ and tbl_user_mobile.userId= tbl_user.userId 这样就没有问题
或者这样写 delete from tbl_user_mobile where
tbl_user_mobile.userId in (select userIdfrom tbl_user where tbl_user.companyId =’1231’)
那天还遇到了另一个问题中文显示出问题,英文和数字都没有问题,在这种情况下,很有可能就是编码问题导致的。
所以可以先设置浏览器的编码方式,中文一般就是utf-8或者GBK。