我有两个大表,每个表都有超过1000万条记录。我正在尝试找出表之一缺失的值。该表具有相同的架构,如下所示
表格1
| ColA | ColB | ColC |
|:-----------|------------:|:------------:|
| John | Steve | Richardson |
| Steve | Richard | Johnson |
| Will | Jack | Jackson |
表2
| ColA | ColB | ColC |
|:-----------|------------:|:------------:|
| John | Steve | Richardson |
| Will | Jack | Jackson |
我在寻找史蒂夫·理查德·约翰逊(Steve Richard Johnson)的唱片
我尝试了以下查询,但超时
SELECT *
FROM `Table1` AS a
WHERE NOT EXISTS
(SELECT * FROM `Table2` AS b WHERE
`a`.`ColA` = `b`.`ColA` AND `a`.`ColB` = `b`.`ColB` AND `a`.`ColC` = `b`.`ColC`)
最佳答案
将t1的table2左联接应用以获取不匹配的行,如下所示
select t1.*
from table1 t1
left join Table2 t2 on t1.col1A = t2.colA and t1.colB = t2.colB and t1.colC = t2.colC
where t2.colA is null and t2.cOlB is null and t2.colC is null
关于mysql - 比较两个大表中的多行,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42266756/