有一sql语句写不来?大家帮帮忙

caoit 2005-03-31 11:16:00
现有表 table1与table2,其字段相同([姓名] varchar(10)),现要得到table1中在table2中没有的姓名。sql怎么写
...全文
148 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
ningmeng3000 2005-04-01
  • 打赏
  • 举报
回复
楼主阿,小心上面的回复阿.他们有好多都将from写成form了,这样会出错的

这句才对的:
select name from table1 where name not in (select name from table2)
LIHY70 2005-04-01
  • 打赏
  • 举报
回复
select * from table1
where name not in(slect name form table2)
zhangzs8896 2005-04-01
  • 打赏
  • 举报
回复
select * from table1 a
where not exists (select * from table2 where 姓名=a.姓名)
或者
select * from table1
where 姓名 not in(slect 姓名 form table2)
paoluo 2005-03-31
  • 打赏
  • 举报
回复
第一句语法有问题,只能用第二句。
paoluo 2005-03-31
  • 打赏
  • 举报
回复
感觉是第二句。

但是第二句有点小问题,要改一下。

select * from table1 where name not in (select Distinct name from table2)
caoit 2005-03-31
  • 打赏
  • 举报
回复
上面两句那个效率高点
friendliu 2005-03-31
  • 打赏
  • 举报
回复
select * from table1 where name not in(slect name form table2)
lakers_ren 2005-03-31
  • 打赏
  • 举报
回复
select name from table1 where name not exist in (select name from table2)

34,576

社区成员

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

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