求不存在记录

编程有钱人了 2012-11-07 12:18:10
A表
E_Word nvarchar(400)
E_HY nvarchar(20)
E_LAN nvarchar(8)
三个字段

B表也是这个三个字段
E_Word nvarchar(400)
E_HY nvarchar(20)
E_LAN nvarchar(8)

我用
select top 20 * from A表 order by newid();
//从A表随即取出20条 放到B表里去
//下次再取的时候 如果B表里存在 就不取了
//这个SQL语句怎么写?
//因为这是随即取的 我不知道怎么写才效率高
...全文
105 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
编程有钱人了 2012-11-07
  • 打赏
  • 举报
回复
引用 4 楼 lixzhong 的回复:
SQL code1234567 select top 20 * from ( select E_Word,E_HY,E_LAN from A except select E_Word,E_HY,E_LAN from B) as TB where xxx='xxx' order by NEWID()
谢谢了 吃完午饭结贴
發糞塗牆 2012-11-07
  • 打赏
  • 举报
回复
给抢了... select top 20 * from a where not exists (select 1 from b where a.E_Word=b.E_Word and a.E_HY =b.E_HY and a.E_LAN=b.E_LAN) order by newid() 1楼的要2005以后才能用
开启时代 2012-11-07
  • 打赏
  • 举报
回复
  select top 20 * from 
  (
  select E_Word,E_HY,E_LAN from A
  except
  select E_Word,E_HY,E_LAN from B) as TB
  where xxx='xxx'
  order by NEWID()
编程有钱人了 2012-11-07
  • 打赏
  • 举报
回复
引用 1 楼 ssp2009 的回复:
select top 20 * from A表 except select * from B表 order by newid();
如果A表后面有where 条件的话 这个SQL怎么写?
开启时代 2012-11-07
  • 打赏
  • 举报
回复
  select top 20 * from 
  (
  select E_Word,E_HY,E_LAN from A
  except
  select E_Word,E_HY,E_LAN from B) as TB
  order by NEWID()
快溜 2012-11-07
  • 打赏
  • 举报
回复
select top 20 * from A表 except select * from B表 order by newid();

27,579

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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