mysql - 如何从具有三个主键的两个表中删除多行?

标签 mysql

我正在尝试从两个表(即 pdn_subscription_ctx 和Subscriber_profile)中删除从复选框中选择的多行,这两个表具有 mysqldb 中的三个主键 mcc、mnc 和 msin,但我无法做到这一点。这是我写的命令:

DELETE x.*
     , p.* 
  FROM pdn_subscription_ctx x
  JOIN subscriber_profile p
    ON x.mcc = p.mcc 
   AND x.mnc = p.mnc 
   AND x.msin = p.msin 
 WHERE (p.mcc,p.mnc,p.msin) IN ( (244, 56, "0x1000000004"),(244, 59, "0x1000000002"),(289, 88, "0x1000000001" ) )

它不会删除任何行,也不会显示错误。 以下是 pri.key 字段的示例数据: mcc mnc msin 244 56 0x1000000004

最佳答案

假设你的模型和我的模型是等效的,你的代码就可以正常工作

drop table if exists pdn_subscription_ctx , subscriber_profile ;
create table pdn_subscription_ctx(mcc int,mnc int ,msin varchar(20));
create table subscriber_profile(mcc int,mnc int ,msin varchar(20));
insert into pdn_subscription_ctx values
(244, 56, "0x1000000004"),(244, 59, "0x1000000002"),(289, 88, "0x1000000001");
insert into subscriber_profile values
(244, 56, "0x1000000004"),(244, 59, "0x1000000002"),(289, 88, "0x1000000001");

DELETE pdn_subscription_ctx.*, subscriber_profile.* 
FROM pdn_subscription_ctx 
INNER JOIN subscriber_profile ON pdn_subscription_ctx.mcc = subscriber_profile.mcc AND 
                pdn_subscription_ctx.mnc = subscriber_profile.mnc AND 
                pdn_subscription_ctx.msin = subscriber_profile.msin 
WHERE (subscriber_profile.mcc,subscriber_profile.mnc,subscriber_profile.msin) IN ( (244, 56, "0x1000000004"),(244, 59, "0x1000000002"),(289, 88, "0x1000000001" ))
;

select * from pdn_subscription_ctx;
Empty set (0.00 sec)

select * from subscriber_profile; 
Empty set (0.00 sec)

关于mysql - 如何从具有三个主键的两个表中删除多行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57687604/

相关文章:

c# - 在下拉列表中显示不同的日期时间列

c# - mysql select 查询中的可选参数

mysql - Rails 3.1 破坏了 MySql::Time 的排序

php - 同一患者的不同订单号只能让我从 DB 获取一份

sql - (mySQL) 无法正确查询 2 个表的数据

python - 使用Python从数据库表中测量纬度和经度坐标之间的距离

c# - 访问 DBSet 时出现 NullReferenceException。使用 MySQL、EF6

mysql - 什么是 mysql 查询的合理时间?

mysql - SSRS 在数据集中的单个列上选择不同

php - 在 Laravel 中搜索部分匹配项