提取表和子查询的区别(derived table vs subqueries)

子查询,大家再熟悉不过了,例如

select employee_name
from employee
where employee_salary >

(select avg(employee_salary)
from employee
)

下面这也是一个子查询,没用到where语句。

INSERT INTO math_study_group(id, name)
SELECT id, name
FROM student_details WHERE subject= 'Math'


下面粗体部分是提取表(derived table)

delete from id  where Id not in

 (select min(id)

from

(select id,peopleId from people)as a 

GROUP by peopleId );

两者的区别就是

- derived tables are used in the FROM clause
- subqueries are used in the WHERE clause, but can also
be used to select from one table and insert into
another as we showed above

翻译过来就是

提取表是用在 from 语句中的。

子查询是用在 where语句中的,但是也可以用在从一张表中查询,然后插入到另一张表,就像上面展示的那个例子一样。



  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值