Home > Database > Mysql Tutorial > mysql子查询命令_MySQL

mysql子查询命令_MySQL

WBOY
Release: 2016-06-01 13:29:08
Original
971 people have browsed it

mysql子查询命令

 

1、EXISTS和NOT EXISTS操作符只测试某个子查询是否返回了数据行。如果是,则EXISTS将是true. NOT EXISTS将是false.

如:

 

[sql] select exitsts (select * from absence);    select not exists (select * from absence);  
Copy after login

2、与主查询相关的子查询需要引用主查询里的值,所以必须依赖于主查询。因为这种联系,与主查询相关的子查询不能脱离主查询作为一条独立的查询命令去执行。

如:

[sql] select j from t2 where (select i from t1 where i=j);  
Copy after login

 

 

 

与主查询相关的子查询的工作情况是:把值从主查询传递到子查询,看它们是否满足在子查询里给出的条件。

 

3、有相当一部分使用了子查询的命令可以被改写成一个联结查询。有时候,联结查询要比子查询的执行效率更高,所以把子查询改写成联结查询是个不坏的主意。

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