当前位置:网站首页>多表查询
多表查询
2022-07-27 16:08:00 【zh_Tnis】
多表查询:在查询为多张表的数据时,通常在from表和表之间使用逗号,作为间隔符号。
1.内连接inner join,相当于两个集合关键字段的全交叉记录。
- 1:select * from table_name1 inner join table_name2;
- 2:select * from table_name1,table_name2;

2.等值连接,将有等值条件筛选的称为等值连接,也就是相同外键约束的组合。
- 1:select * from table_name1 inner join table_name2 on table_name1.col_name=table_name2.col_name;
- 2:select * from table_name1,table_name2 where table_name1.col_name=table_name2.col_name;

3.外连接。
- 左连接left join:select * from table_name1 left jion table_name2 on table_name1.id=table_name2.id;
存在两张表,其中a表作为主表,b表作为副表,a表的记录数多于b表的话,那么当a表为主表显示时候,b表中的记录不够则自动用null去填充。

- 右连接right join:select * from a right join b on a.id=b.id;
同左连接思想一样,但是这个右连接的主表是b,副表是a,其他与左连接相似,当副表记录不够时用null填充。

4.全连接。
MySQL的全连接关键字是Union和Union all,而不是full join,full join关键字是Oracle中存有的。
- (select * from table_name1) union (select * from table_name2);

注意:
1.通过全连接union连接的两张表的列数必须相同。
2.合并的两张表中以第一张表作为主要表,也就是他们合并的记录取值的字段是第一张表的字段,而第二张表的字段消失。
3.通常来说,我们一般采用的全连接是union all进行合并,因为union耗时较长。
4.union连接的SQL字句,单个字句不写order by,因为不会存有排序的效果。
边栏推荐
- Exciting collection of new features released by salesforce
- Multi thread implementation loop
- 防止sql注入
- org.gradle.api.UncheckedIOException: Could not load properties for module ‘gradle-kotlin-dsl‘ from C
- 查看端口PID及结束进程
- Golang worker pool
- 知物由学 | SO加固如何提升Android应用的安全性?
- XStream reports an error abstractreflectionconverter$unknownfield exception when parsing XML
- 1542. 找出最长的超赞子字符串 哈希+状态压缩
- [learning notes] the implementation principle of the ordered set Zset in redis - skip table
猜你喜欢

How can we carry out NLP cross language knowledge transfer?

登录页面tableLayout(表格布局)

Salesforce certified sharing and visibility Designer (su20) certification examination summary

Evaluation index of machine learning (II) -- classification evaluation index

Six relationships of classes -- the difference between dependency and Association

Localization within Communities

The Ministry of industry and information technology re governs data security, and Netease Yidun "privacy compliance" keeps the bottom line of enterprise operation

浅论分布式训练中的recompute机制

Set up SSO based on SAML 2.0 in salesforce and enable JIT user provisioning (between SF orgs / between SF org and experience cloud / other IDPs)

Salesforce File Share and Security
随机推荐
知物由学 | APP大瘦身,新一代AAB框架下的安全加固之道
Buffer的只读模式
CFA exam registration instructions
Yanrong technology was selected as Beijing's "specialized and innovative" in 2022 to lead hybrid cloud file storage
The latest advanced interview questions for big factories are necessary
hutool- 数字计算
golang 并发缓存击穿或合并请求
JS中的冒泡排序
[learning notes] classification of locks in the database
Convolutional neural network -- from r-cnn, fast r-cnn to fast r-cnn, mask r-cnn
MySQL adds users and grants query only permission
Operation of simulated examination platform for 2022 low voltage electrician examination questions
快速获取网站媒体资源方法
展锐鲜苗:赋能全场景应用,海量数据需要AI与IoT融合
org.apache.catalina.core.StandardContext.startInternal Context [] startup failed due to previous err
Salesforce dynamic dashboard dynamic reports, limitations and Solutions
Hutool string utility class
Evaluation index of machine learning (I) -- regression evaluation index
Learn from things | Yidun mobile terminal isomorphism practice, improve the official website interaction experience in a few steps
[introduction to database system (Wang Shan)] Chapter 4 - Database Security