select 问题

jing1979 2000-05-09 10:47:00
1. select title_id,title,price from titles where title_id in (select title_id from sales where qty>2)

2. select title_id,title,price from titles where exists (select * from sales where sales.title_id=titles.title_id and qty>2)

3. select a.title_id,a.title,a.price from titles a,sales b where a.title_id=b.title_id and b.qty>2 order by a.title_id

环境:mssql70 database:pubs
在前面两个都是返回同样的结果。但第三个就不一样了。按道理应该返回相同的。
我分析了一下,发现第三个返回有相同的title_id(BU1032) 。但在titles只有一条(BU1032) ,我的这条语句where 条件用default应该是inner.为什么会出现相同的记录呢????????????
...全文
158 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
Tyro 2000-05-22
  • 打赏
  • 举报
回复
如果sales中title_id为BU1032的纪录不只有一条的话,就会有相同的纪录出现
haihong 2000-05-22
  • 打赏
  • 举报
回复
跟关键字无关,重要的是sales表中有没有重复的title_id
huitor 2000-05-22
  • 打赏
  • 举报
回复
为什么会出现相同的记录?
如果sales只有一个关键字title_id,肯定1和3返回同样的结果。问题是sales有多个关键字。
请再仔细检查,sales中应该有多条纪录,其title_id=BU1032。
jing1979 2000-05-10
  • 打赏
  • 举报
回复
to LaoZheng
你是什么意思,有外联。我要限制。用inner,我的问题是什么??


jing1979 2000-05-10
  • 打赏
  • 举报
回复
to LaoZheng
你是什么意思,用外联??。我要限制,用inner,我的问题是什么??


jing1979 2000-05-10
  • 打赏
  • 举报
回复
你是什么意思,我说的BU1032肯定是存在的。
你在什么环境下用的??你是不是自己删掉了???
jing1979 2000-05-09
  • 打赏
  • 举报
回复
我用第四条语句得到同第三条一样的结果。?????
4.select a.title_id from titles a inner join sales b on a.title_id=b.title_id where b.qty>2 order by a.title_id

为什么会有相同记录出现?????
LaoZheng 2000-05-09
  • 打赏
  • 举报
回复
titles的某一Title_id在 sales中不存在!
LaoZheng 2000-05-09
  • 打赏
  • 举报
回复
select a.title_id,a.title,a.price from titles a,sales b where a.title_id *=b.title_id and b.qty>2 order by a.title_id

34,588

社区成员

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

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