子查询与连接查询

子查询与连接查询

1,表关联的效率要高于子查询,因为子查询走的是笛卡尔积
2,表关联可能有多条记录,子查询只有一条记录,如果需要唯一的列,最好走子查询

1、如果只需要返回 一个表的数据,建议用exists 或者in。


2、如果要返回2个或多个表的数据,那么就用关联。

例: 查询选修了080110课程学生的姓名

select sname from Student,Score where Student.sno = Score.sno
and cno ='080110'

select sname from Student where sno in(
  select sno from Score where cno='080110'
)
原文地址:https://www.cnblogs.com/tangjiang-code/p/7774823.html