当前位置: 代码迷 >> Sql Server >> 急这样的SQL查询用一条语句如何写出
  详细解决方案

急这样的SQL查询用一条语句如何写出

热度:51   发布时间:2016-04-27 21:30:01.0
急:这样的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)

  相关解决方案