求一个sql语句:两个表相联接查询
求一个sql语句:两个表相联接查询,A表和B表,A表中有categoryID,B表中有oldcategoryID,现在的做法是从A表中找到其categoryID与B表中oldcategoryID不一样的数据!并按A表中的categoryID分组,并去除重复的categoryID.也就是每个categoryID的分类只显示一条!
------解决方案--------------------select distinct categoryID
from A
where not exists(select 1 from B where A.categoryID=B.oldcategoryID)
------解决方案--------------------SELECT categoryID FROM A
WHERE NOT EXISTS(SELECT 1 FROM B WHERE A.categoryID=B.oldcategoryID)
GROUP BY categoryID
------解决方案--------------------select categoryid from a表 a
where not exists(select 1 from b表 where a.categoryid=b.oldcategoryid) --多了个b.
group by categoryid
select categoryid from a表 a
where not exists(select 1 from b表 where a.categoryid=oldcategoryid)
group by categoryid