当前位置:网站首页>多表操作-子查询
多表操作-子查询
2022-07-05 11:37:00 【汤键.TJ】
目录
基本概念
- 查询语句中嵌套了查询语句,我们就将嵌套的查询称为子查询
常见的三种情况
- 表的数据准备请点击查看
结果是单行单列的
- 作用:可以将查询的结果作为另一条语句的查询条件,使用运算符判断
- 查询语法:
- select 列名 from 表名 where 列名=(select 列名 from 表名 [where 条件]);
- 例:查询年龄最大的用户姓名

-- 查询年龄最大的用户姓名 SELECT name,age FROM user WHERE age=(SELECT MAX(age) FROM user);结果是多行单列的
- 作用:可以作为条件,使用运算符in或not in进行判断
- 查询语法:
- select 列名 from 表名 where 列名 [not] in (select 列名 from 表名 [where 条件])
- 例:查询张三和李四的订单信息

-- 查询张三和李四的订单信息 SELECT * FROM orderlist WHERE uid IN (SELECT id FROM user WHERE name IN ('张三','李四'));
结果是多行多列的
- 作用:查询的结果可以作为一张虚拟表参与查询
- 查询语法:
- select 列名 from 表名 [别名],(select 列名 from 表名 [where 条件]) [别名] [where 条件];
- 例:查询订单表中id大于4的订单信息和所属用户信息

-- 查询订单表中id大于4的订单信息和所属用户信息 SELECT u.name, o.number FROM user u, (SELECT * FROM orderlist WHERE id>4) o WHERE o.uid=u.id;
边栏推荐
- pytorch-softmax回归
- 全网最全的新型数据库、多维表格平台盘点 Notion、FlowUs、Airtable、SeaTable、维格表 Vika、飞书多维表格、黑帕云、织信 Informat、语雀
- 【Win11 多用户同时登录远程桌面配置方法】
- C operation XML file
- Is it difficult to apply for a job after graduation? "Hundreds of days and tens of millions" online recruitment activities to solve your problems
- Crawler (9) - scrape framework (1) | scrape asynchronous web crawler framework
- Solve the problem of slow access to foreign public static resources
- [crawler] Charles unknown error
- SET XACT_ ABORT ON
- Harbor镜像仓库搭建
猜你喜欢

idea设置打开文件窗口个数
![[crawler] Charles unknown error](/img/82/c36b225d0502f67cd04225f39de145.png)
[crawler] Charles unknown error

COMSOL--三维图形的建立

谜语1

全网最全的新型数据库、多维表格平台盘点 Notion、FlowUs、Airtable、SeaTable、维格表 Vika、飞书多维表格、黑帕云、织信 Informat、语雀

中非 钻石副石怎么镶嵌,才能既安全又好看?

Mongodb replica set

Is it difficult to apply for a job after graduation? "Hundreds of days and tens of millions" online recruitment activities to solve your problems

【TFLite, ONNX, CoreML, TensorRT Export】

高校毕业求职难?“百日千万”网络招聘活动解决你的难题
随机推荐
石油化工企业安全生产智能化管控系统平台建设思考和建议
[calculation of loss in yolov3]
C # implements WinForm DataGridView control to support overlay data binding
【爬虫】wasm遇到的bug
Guys, I tested three threads to write to three MySQL tables at the same time. Each thread writes 100000 pieces of data respectively, using F
How to protect user privacy without password authentication?
7 大主题、9 位技术大咖!龙蜥大讲堂7月硬核直播预告抢先看,明天见
【爬虫】charles unknown错误
MySQL 巨坑:update 更新慎用影响行数做判断!!!
以交互方式安装ESXi 6.0
[yolov5.yaml parsing]
redis的持久化机制原理
解决readObjectStart: expect { or n, but found N, error found in #1 byte of ...||..., bigger context ..
[leetcode] wild card matching
2048 game logic
How to get a token from tokenstream based on Lucene 3.5.0
pytorch-权重衰退(weight decay)和丢弃法(dropout)
pytorch-softmax回归
Technology sharing | common interface protocol analysis
How to make your products as expensive as possible


