这条 not exists 表达式如何写
数据库使用MS SQL 2000,
有两上表,我想找出两个表里两个工单号某一列的差异(类似 sql2008 的except功能),
查询adatabase 工单号Work_order='131A-13070298'号的PCBSN
SELECT DISTINCT a.PCBSN
FROM adatabase a
WHERE a.Work_order='131A-13070298'
SELECT DISTINCT b.PCBSN
FROM bdatabase b
WHERE b.Work_order='131a-13070243'
SELECT DISTINCT PCBSN
FROM adatabase a
WHERE a.Work_order='131A-13070298'
and NOT EXISTS
(
SELECT b.PCBSN
FROM bdatabase b
WHERE b.Work_order='131a-13070243'
AND a.PCBSN = b.PCBSN
)
--a表中工单号相同但版本号b表中不存在的记录
select *
from adatabase a
where not exsists(select 1 from bdatabase b where b.Work_order=a.Work_order and a.PCBSN=b.PCBSN)
--b表中工单号相同但版本号a表中不存在的记录
select *
from bdatabase a
where not exsists(select 1 from adatabase b where b.Work_order=a.Work_order and a.PCBSN=b.PCBSN)
SELECT *
FROM
(
SELECT DISTINCT a.PCBSN
FROM adatabase a
WHERE a.Work_order='131A-13070298'
) a
FULL JOIN
(
SELECT DISTINCT b.PCBSN
FROM bdatabase b
WHERE b.Work_order='131a-13070243'
) b
ON a.PCBSN = b.PCBSN
WHERE a.PCBSN IS NULL OR b.PCBSN IS NULL
SELECT DISTINCT a.PCBSN
FROM adatabase a
WHERE a.Work_order='131A-13070298'
and not exists
(SELECT 1
FROM bdatabase b
WHERE b.Work_order='131a-13070243' and b.PCBSN=a.PCBSN)