gpt4 book ai didi

mysql - SQL 根据 2 个关键参数仅获取 2 个表之间的不同条目

转载 作者:行者123 更新时间:2023-11-29 19:18:47 25 4
gpt4 key购买 nike

基本上我有两个具有相同结构的表(Accounts 和 New_accounts)。 New_accounts 的条目比 Accounts 更多,因此我只需要获取 Accounts 中不存在的条目。

不幸的是我只能按不同的 ID 对它们进行排序。两个表之间唯一需要依赖的相同之处是 dist_abbvvip_id 的组合对。任何条目上都不会有相同的一双。因此,条目 A 将具有 dist_abbvvip_id 的组合,该组合仅对该条目是唯一的。这是判断它是否存在于两个表中的方法。

表字段:

id | name | address | city | state | zip | phone | email | vip_id | dist_abbv

我尝试过这个,但我知道(通过行数)这不会返回准确的条目

SELECT new_accounts.*
FROM new_accounts
LEFT JOIN accounts
ON (accounts.vip_id = new_accounts.vip_id AND accounts.name = new_accounts.name)
WHERE (accounts.vip_id = new_accounts.vip_id AND accounts.name = new_accounts.name) IS NULL

最佳答案

尝试将 WHERE 子句更改为

WHERE accounts.vip_id is NULL AND accounts.name is NULL

希望这有帮助。

关于mysql - SQL 根据 2 个关键参数仅获取 2 个表之间的不同条目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42547137/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com