Home > Database > Mysql Tutorial > body text

小贝_mysql三种子查询_MySQL

WBOY
Release: 2016-06-01 13:00:07
Original
1160 people have browsed it

mysql三种子查询

简要:
一、三种子查询
二、三种子查询理解模型

 

一、mysql 三种子查询

where子查询、from子查询、exists子查询

 

二、理解模型:

2.1、一个好的模型,便于我们去理解。当我们编写一条sql语句时,可以通过以下几点去理解:

a、where表达式,把表达式放在行中,看表达式是否为真

b、列: 理解成变量,可以运算

c、 取出结果,可以理解成一张临时表

2.2、理解三种子查询

1、where子查询

把内层查询的结果当做是外层查询的比较条件

详细: select 字段 from 表 where 内层结果

执行: 先执行where后的语句,得到内层结果。再执行外层

 

2、from子查询

把内层查询结果当成临时表,供外层sql再次查询

详细: select 字段 from (from子查询)

执行: 先执行from后的语句,得到内层结果。再执行外层

 

3、exists子查询

把外层查询结果,拿到内层。看内层的查询是否成立。

这个过程是从往外层的查询结果,一行一行代入内层中,判断是否成立。即exists后面的语句是否为真。如果为真,则显示代入的这一行。相反则不用。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!