当前位置:网站首页>Different usage scenarios of subqueries as retrieval tables and the question of whether to add aliases
Different usage scenarios of subqueries as retrieval tables and the question of whether to add aliases
2022-07-30 06:05:00 【Just go and be safe~】
For more details, please refer to the [Subquery] subsection under [Data Analysis Advanced Road Column]
1, subquery
Subquery refers to a query in which a query statement is nested inside another query statement. This feature has been introduced since MySQL 4.1.The subquery is calculated first in the SELECT clause, and the result of the subquery is used as the filter condition of another query in the outer layer. The query can be based on one table or multiple tables.Commonly used operators in subqueries are ANY (SOME), ALL, IN, EXISTS.
Subqueries can be added to SELECT, UPDATE and DELETE statements, and can be nested multiple levels.Comparison operators such as "<", "<=", ">", ">=", and "!=" can also be used in subqueries.
The main points of its attention include the following:
- The result of one query is used as the condition of another query
- There is a nesting of queries, the inner query is called a subquery
- Use parentheses for subqueries
Subqueries are mainly divided into the following three cases, the corresponding cases are as follows:
1. A single row and a single column means that the result is one such as 1. In this case, no alias is required
2. Multiple rows and single columnsThat is, the result is a set of data such as (1, 2, 3). In this case, no alias is required.
3. Multiple rows and multiple columns means the result is a table. In this case An alias is required to access fields in the table
2. The result of the subquery is a single row and a single column
Example: Query the product information with the highest price by means of sub-query
# Through sub-query, query the product information with the highest price
-- 1. First query the highest price
SELECT MAX(price) FROM products;
-- 2. Use the highest price asConditions, get product information
边栏推荐
- 2022年SQL大厂高频实战面试题(详细解析)
- Path dependence: the poor hard science to counter attack breakthrough
- Concurrent Programming Review
- PyCharm使用教程(较详细,图+文)
- [Mysql] DATEDIFF function
- How MySQL to prepare SQL pretreatment (solve the query IN SQL pretreatment can only query out the problem of a record)
- 2022 SQL big factory high-frequency practical interview questions (detailed analysis)
- MYSQL-InnoDB的线程模型
- 手把手教你设计一个CSDN系统
- MySQL 灵魂 16 问,你能撑到第几问?
猜你喜欢
JVM之GC 调优基础知识(一)
微信小程序开发学习
从想当亿万富翁到职场、创业、爱情、抑郁、学医学武,我的程序人生
MySql模糊查询大全
腾讯面试居然跟我扯了半小时的CountDownLatch
解决没有配置本地nacos但是一直发生localhost8848连接异常的问题
JVM之GC 调优工具 Arthas 实战使用(二)
【图像检测】基于灰度图像的积累加权边缘检测方法研究附matlab代码
留念 · 大学时代最后的系统设计图
Learn FPGA from the underlying structure (6) ---- Distributed RAM (DRAM, Distributed RAM)
随机推荐
2022年比若依更香的开源项目
2022 Pengcheng Cup web
php数组实现根据某个键值将相同键值合并生成新二维数组的方法
MySql模糊查询大全
参与开源,让程序员找回热血和激情
[Image processing] Image skeleton extraction based on central axis transformation with matlab code
Internet (software) company project management software research report
Error: npm ERR code EPERM
MySql的初识感悟,以及sql语句中的DDL和DML和DQL的基本语法
JVM之GC 调优工具 Arthas 实战使用(二)
分布式事务之 Atomikos 原理和使用(一)
navicat新建数据库
MySql string splitting realizes the split function (field splitting, column switching, row switching)
如何使用FirewallD限制网络访问
程序员大保健指南,给自己的身心偶尔放松的机会
解决phpstudy无法启动MySQL服务
The use of Conluce, an online document management system
JVM面试总结
是时候不得不学英语了,技多不压身,给自己多条路
cookie和session区别