简体   繁体   English

MySQL两个独立的表,它们的联接在第三个表中不存在

[英]MySQL two independent tables whose join do not exist in third table

I have three tables A (Master), B (Master) and C (Transaction). 我有三个表A(主),B(主)和C(交易)。 The combination of A.id and B.id exists in C. I want that data of A where combination of A.id and B.id do not exist in table C. C中存在A.id和B.id的组合。我希望表C中不存在A.id和B.id组合的A数据。

I tried the following but get no rows selected. 我尝试了以下操作,但未选择任何行。

SELECT A.* from A, B, C where A.id != C.id and B.id != C.id 从A,B,C中选择A. *,其中A.id!= C.id和B.id!= C.id

I am not that good at creating queries. 我不太擅长创建查询。

Can someone please form a query for this? 有人可以对此进行查询吗?

SELECT * 
FROM A 
WHERE A.id NOT IN (
    SELECT Aid FROM C)

Your question is a bit strange though, this query selects all the id's of A which are not in table C. 但是您的问题有点奇怪,此查询选择表C中未包含的所有A的ID。

SELECT A.*, B.* 
FROM A , B
WHERE A.id = B.id AND A.id NOT IN (SELECT Aid FROM C) AND B.id NOT IN (SELECT Bid FROM C)

SELECT * FROM A,C B.id = A.id上的左联接B B.id = C.id上的左联接B在A.id = C.id和B.id为NULL的情况下

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM