怎么从一个有全部记录的表里面找出在另一个表里面没有对应用户id的记录?在线等!

zengting2002 2005-06-10 05:08:50
表1:id,name
表2:id,name
但是表1包含所有用户,表2中只有少数用户的信息。
怎样从表1中找出表2没有包含的用户的记录?
...全文
62 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
子陌红尘 2005-06-10
  • 打赏
  • 举报
回复
select a.* from t1 a where not exists(select 1 from t2 where id=a.id and name=a.name)
gslrq 2005-06-10
  • 打赏
  • 举报
回复
用 NOT IN
zengting2002 2005-06-10
  • 打赏
  • 举报
回复
ok,done。
正确答案是:
select * from t1 left join t2 on t1.id=t2.id where t2.id is null
631799 2005-06-10
  • 打赏
  • 举报
回复
select t1.* from t1 left join t2 on t1.id=t2.id where t2.id is null
zengting2002 2005-06-10
  • 打赏
  • 举报
回复
select * from t1 where not exists(select * from t2 where id=t1.id)

服务器: 消息 156,级别 15,状态 1,行 1
在关键字 'not' 附近有语法错误。

--------------------------------------------------------
select * from 表1 where name not in (select name from 表2)
这个思维我早试过了,不行的。
rea1gz 2005-06-10
  • 打赏
  • 举报
回复

http://community.csdn.net/Expert/topic/4074/4074053.xml?temp=3.107852E-02
wangdehao 2005-06-10
  • 打赏
  • 举报
回复
select * from 表1 where name not in (select name from 表2)
wangdehao 2005-06-10
  • 打赏
  • 举报
回复
select * from 表1 where name not in (select name from 表2)
pbsql 2005-06-10
  • 打赏
  • 举报
回复
select * from t1 where not exists(select * from t2 where id=t1.id)

34,594

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧