当前位置:网站首页>Usage of MySQL subquery keywords (exists)

Usage of MySQL subquery keywords (exists)

2022-07-07 21:14:00 1024 questions

Catalog

1. all

1.1 Format

1.2 characteristic  

1.3 operation

2. any(some)

1.1 Format

1.2 characteristic

1.3 operation

3. in

1.1 Format

1.2 characteristic

1.3 operation

4. exist

1.1 Format

1.2 characteristic

1.3 operation

1.4 explain

1. all1.1 Format

1.2 characteristic  

all: Compared with all the values returned by the subquery, it is true Then return to true

all It can be done with =,>=,>,<,<=,<> Use a combination of , Respectively equal to , Greater than or equal to , Greater than , Less than , Less than or equal to , Not all the data in it

Greater than all Indicates that the value in the specified column must be greater than each value in the subquery set , That is, it must be greater than the maximum value of the sub query set ; If it is less than, it is less than the minimum value in the sub query .

1.3 operation

2. any(some)1.1 Format

1.2 characteristic

any: Compared with all the values returned by the subquery, it is true Then return to true

any It can be done with =,>=,>,<,<=,<> Use a combination of , Respectively equal to , Greater than or equal to , Greater than , Less than , Less than or equal to , Not equal to any of the data

Greater than any Indicates that the value in the specified column must be greater than any value in the subquery set , The subset to be queried must be greater than the smallest ; Others in the same way

some It can be understood as any Another name for

1.3 operation

3. in1.1 Format

1.2 characteristic

in Used to determine the value of a record , Whether in the specified set

stay in Add... Before the keyword not You can reverse the conditions

1.3 operation

4. exist1.1 Format

1.2 characteristic

The subquery if “ There are data results ”( Return at least one row of data ), Then EXISTS() The result is :true, Outer query execution

The subquery if “ No data results ”( No data returned ), Then EXISTS() The result is :false, The outer query does not execute

EXISTS The following sub query does not return any actual data , Only return true or false , When true is returned where Conditions established

Be careful :EXISTS keyword , Than IN The operation efficiency of keywords is high , therefore , In actual development , Especially when there is a large amount of data , Recommended EXISTS keyword

1.3 operation

1.4 explain

When querying an outer query , The outer query is executed row by row , When the first line is executed , Determine whether the subquery is true, by true Then this line of data is found , Then the second line queries ... In reciprocating .

The above is personal experience , I hope I can give you a reference , I also hope you can support the software development network .


原网站

版权声明
本文为[1024 questions]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/188/202207071838134420.html