日期:2014-05-19  浏览次数:20406 次

急:这样的SQL查询用一条语句怎么写出?
有两个表

Table1
-----------------
ID     P_name  
1           A
2           B
3           C
4           D
5           E
6           F

Table2
-----------------
ID       P_name
1               A
2               B
3               C

在第一个表里面求出,   在第二个表里面没有的记录RECORDCOUNT

也就是求出第一个表里如下记录(第二个表里没有的记录)
---------------------------------
ID       P_NAME
4           D
5           E
6           F

这个记录是第二个表里面没有的记录.

这样的SQL查询用一条语句怎么写出


------解决方案--------------------
select b.* from table1 a,table2 b where a.ID <> b.ID
------解决方案--------------------
select * from table1
where p_name not in(
select p_name from table2)
------解决方案--------------------
select a.* from table1 a,table2 b where a.ID <> b.ID

------解决方案--------------------
select * from Table1 where ID not in(select ID from Table2)