第一个答案:select [name],class,c.cno from card as c inner join ( select b.bno,b.cno from borrow as b inner join
( select bno,bname from books where bname='水浒')as a on (b.bno=a.bno) ) as b on(b.cno=c.cno)第二个答案
select * from card c where exists(select * from borrow as b,books a where a.bname='水浒' and b.bno=a.bno and b.cno=c.cno)我发现结果一样,但是exists感觉用起来很简洁,不知道如果在百万条数据以上,是否会影响性能?
( select bno,bname from books where bname='水浒')as a on (b.bno=a.bno) ) as b on(b.cno=c.cno)第二个答案
select * from card c where exists(select * from borrow as b,books a where a.bname='水浒' and b.bno=a.bno and b.cno=c.cno)我发现结果一样,但是exists感觉用起来很简洁,不知道如果在百万条数据以上,是否会影响性能?
--
select * from card c where exists(select * from borrow as b,books a where a.bname='水浒' and b.bno=a.bno and b.cno=c.cno)
--改成下面这样效率更快
select * from card c where exists(select 1 from borrow as b,books a where a.bname='水浒' and b.bno=a.bno and b.cno=c.cno)
----测试语句时间set statistics time on
select * from sysprotects
set statistics time off
不需要采用链接的形式
推荐使用第二种 exists
显示 执行SQL语句 select * from sysprotects 所花的时间