当前位置:网站首页>内连接和左连接简单案例
内连接和左连接简单案例
2022-07-29 03:45:00 【月阴荒】
内连接也被称为等同连接,返回的结果集是两个表中所有相匹配的数据,而舍弃不匹配的数据。也就是说,在这种查询中,DBMS只返回来自源表中的相关的行,即查询的结果表包含的两源表行,必须满足ON子句中的搜索条件。作为对照,如果在源表中的行在另一张表中没有对应的行,则该行就被过滤掉,不会包括在结果表中。内连接使用比较运算符来完成。内连接可分为两种。
1.等值连接
使用等于号(=)比较被连接列的列值,在查询结果中列出被连接表中的所有列,包括其中的重复列。
案例:使用INNER JOIN内连接查询
从STUDENT表和TEACHER表中查询学生姓名,所在系,所修的所有课程的课程号以及开课教师姓名。
SELECT SNAME,S.DNAME,S.CNO,TNAME
FROM STUDENT AS S
INNER JOIN TEACHER AS T
ON S.CNO = T.CNO
ORDER BY SNAME
接下来写一下左连接的简单案例
所谓左连接,即 LEFT JION子句,其允许我们从两个或多个数据库表查询数据。
LEFT JION子句 是 SELEC 语句的可选部分,其出现在FROM子句之后。
我们假设要从两个表t1和t2查询数据。以下语句说明了连接两个表的LEFT JOIN 子句的语法:
SELECT
t1.c1,t1.c2,t2.c1,t2.c2
FROM
t1
LEFT JOIN
t2 ON t1.c1 = t2.c1;
当使用LEFT JOIN子句将t1表加入t2表时,如果来自左表t1
边栏推荐
- How fast does it take to implement a super simple programming language?
- Violence recursion to dynamic programming 01 (robot movement)
- Shopify卖家:EDM营销就要搭配SaleSmartly,轻松搞定转化率
- The list is not updated in real time when JS V-for data changes
- Tristate gate
- 3.解决Pycharm报错Unresolved reference ‘selenium‘ Unresolved reference ‘webdriver‘
- Since 2019, you must have stopped using this marketing strategy
- I.MX6U-驱动开发-2-LED驱动
- 深入C语言(1)——操作符与表达式
- Data too long for column 'xxx' at row 1 solution
猜你喜欢
Sleuth+Zipkin 来进行分布式服务链路的追踪
EMD 经验模态分解
Shopify seller: EDM marketing should be combined with salesmartly to easily get the conversion rate
Why is continuous integration and deployment important in development?
Instance setup flask service (simple version)
(codeforce547)C-Mike and Foam(质因子+容斥原理)
机器学习【Numpy】
(nowcoder22529C)dinner(容斥原理+排列组合)
for_ Example of each usage
The latest second edition of comic novels, listening to books, three in one, complete source code / integrated visa free interface / building tutorials / with acquisition interface
随机推荐
Practical application cases of digital Twins - smart energy
Notes on letter symbol marking of papers
RTP 发送 和接收 h265
Anaconda offline installation environment
Inclusion exclusion principle
Simple understanding of CDN, SDN and QoS
Why BGP server is used in sunflower remote control? Automatic optimal route and high-speed transmission across operators
【C语言入门】ZZULIOJ 1031-1035
Getting started with caspin
The difference between int and integer. Is int or integer used in practical applications?
Introduction and comparison of unicast, multicast (target broadcast, multicast), broadcast, flooding, flooding
向日葵远程控制为何采用BGP服务器?自动最优路线、跨运营商高速传输
(newcoder 15079) irrelevant (inclusion exclusion principle)
lodash库常用方法
深入C语言(4)——switch的定义与使用
What have I learned from 200 machine learning tools?
Shopify卖家:EDM营销就要搭配SaleSmartly,轻松搞定转化率
EMD 经验模态分解
Simple understanding of Poe and UPS Technology
Kotlin companion object vs global function