当前位置:网站首页>多表查询
多表查询
2022-07-27 12:32:00 【涟涟涟涟】
多表查询的分类
1.内连接
2.外连接
3.交叉连接(了解)
注:所用图形界面管理器为:Navicat Permium 12
内连接
实质是:多个表的交集。
#user_info表
create table user_info(
id int(2) primary key,
user_name varchar(12) unique,
password varchar(15) not null,
real_name varchar(8) not null,
age int(3)
);
#address表
create table address(
id int(2) primary key,
user_id int(2) not null,
real_name varchar(8),
mobile char(11),
address varchar(150)
);
insert into user_info values(1,'浅唱灬幸福','[email protected]','王晓明',12);
insert into address values(1,1,'王小明','15516472282','山西太原');
insert into address values(2,1,'王鑫','18404905139','山西大同');
insert into address values(3,1,'任建','15333021730','山西晋城');
insert into user_info values(2,'ぅ浮生若梦〤','56701wz','王楠',36);
insert into address values(4,2,'王楠','15010303314','北京海淀');
insert into address values(5,2,'赵婕','18435224278','山西长治');
insert into user_info values(3,'街角の风铃','27w4921','李晓飞',9);
insert into address values(6,6,'刘倩','13159775555','吉林长春');
显式等值连接:
格式:
select ui.*,addr.*
from address addr
join user_info ui on ui.id=addr.user_id;
隐式等值连接:
格式:
select ui.*,addr.* from user_info ui,address addr where ui.id=addr.user_id;
他们虽格式不一,但结果相同
结果:
外连接
外连接分类:
1.左外链接
2.右外链接
3.全外连接(因为全外连接是Oracle里面的所以在此我们只是了解)
左外连接:
特点:以left关键字为参照,关键字左边的表为主表,将其数据全部显示,哪怕从表没有数据
格式:
select ui.*,addr.*
from user_info ui
left join address addr on ui.id =addr.user_id;
结果:
右外连接:
特点:以right关键字为参照,关键字右边的表为主表,将其数据全部显示,哪怕从表没有数据
格式:
select ui.*,addr.*
from address addr
right join user_info ui on ui.id=addr.user_id;
结果:
注:左外连接和右外连接可以相互转化。
例:
左外连接
select ui.*,addr.*
from address addr
left join user_info ui on ui.id =addr.user_id;
右外连接
select ui.*,addr.*
from user_info ui
right join address addr on ui.id=addr.user_id;
结果:
边栏推荐
- How to use the server to build our blog
- STS下载教程(include官网无法下载解决方案)
- Lonely young people can't quit jellycat
- Go Beginner (3)
- In the first half of the year, the number of fires decreased by 27.7%. Guangdong will improve the fire safety quality of the whole people in this way
- 硬刚甲方后:中国移动 4908 万大单被废
- Flash quickly builds an API
- CLS 监控告警:实时保障线上服务高可用性
- 2021-3-22-directed graph sorting
- About the problem that the onapplicationevent method of the custom listener is executed multiple times
猜你喜欢

Bishi journey

最强分布式锁工具:Redisson

The song of the virtual idol was originally generated in this way!

STS download tutorial (the solution cannot be downloaded on the include official website)

2021-3-22-directed graph sorting

Solution: the idea project does not display a tree view

Makefile template

Chapter 8 multithreading

Implicit indicators for evaluating the advantages and disadvantages of automated testing

严控室外作业时间!佛山住建局发文:加强高温期间建筑施工安全管理
随机推荐
Play CSDN editor
Solution: can not issue executeupdate() or executelargeupdate() for selections
HDU1698_Just a Hook
硬刚甲方后:中国移动 4908 万大单被废
I/O实例操作
go 用本地代码replace
[product] about wechat product analysis
Unity shader - Laser special effect shader[easy to understand]
After Party A's hard work, 49.08 million orders of China Mobile were scrapped
【产品】关于微信产品分析
Strictly control outdoor operation time! Foshan housing and Urban Rural Development Bureau issued a document: strengthening construction safety management during high temperature
Fundamentals of mathematics 02 - sequence limit
Makefile template
JVM memory model
You haven't connected to the proxy server. There may be a problem or the address is incorrect (how to check the proxy server IP)
Julia beginner tutorial 2022
Image segmentation vs Adobe Photoshop (PS)
USB network card drive data stream
Simple blockchain day based on bolt database (2)
2021-3-19-byte-face value