两表联合查询,求两表中未关联的数据

2025-03-04 18:51:17
推荐回答(2个)
回答1:

首先假定你表1和表2里的字段名都叫id
然后,你要知道这种查询绝不可以用俩表关联表1.id<>表2.id来做

给你俩方法
1
select * from 表1 where id not in (select id from 表2)

2
select * from 表1 where not exists(select 1 from 表2 where 表1.id=表2.id)

回答2:

给你举个例子
select x,x,x,x,x
from 表1,表2
where 表1.orderid=表2.orderid;