不用子查询,如何查出在一个表中存在而在另一个表中不存在的ID号?
例如:
表t1的主键为Id
表t2也有个主键为Id,并且引用t1的Id
不用子查询,如何查出在表t1中存在而在表t2中不存在的ID号
------解决方案--------------------select * from t1 left join t2 on t1.id=t2.id where t2.id is null
------解决方案--------------------一般就這麼幾種方法
Select * From t1 Where id Not In (Select Distinct id From t2)
Select * From t1 Where Not Exists (Select id From t2 Where id = t1.id)
Select t1.* From t1 Left Join t2 On t1.id = t2.id Where t2.id Is Null
------解决方案--------------------paoluo都说完了
------解决方案----------------------用left join
Select t1.*
From t1
Left Join t2 On t1.id = t2.id
Where t2.id Is Null