连表删除数据

多表联合删除的写法

用户表 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。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值