读书人

求一条经典SQL语句,该如何解决

发布时间: 2012-01-11 22:28:46 作者: rapoo

求一条经典SQL语句
表A(Code NVARCHAR(50),Name NVARCHAR(50))
数据为
A B
B C
C D
表B(Code NVARCHAR(50),Name NVARCHAR(50))
数据为
A B
B C
如何从A表中查询不在B表中的数据
既查出 A表中的行 C D


[解决办法]

SQL code
select * from 表Aexceptselect * from 表B
[解决办法]
另一法,
SQL code
select a.*from 表A aleft join 表B bon a.Code=b.Code and a.name=b.namewhere b.Code is null and b.name is null 

读书人网 >SQL Server

热点推荐