当前位置:网站首页>MySQL winter vacation self-study 2022 11 (9)
MySQL winter vacation self-study 2022 11 (9)
2022-07-06 02:25:00 【Crane paper thousand】
Self association query
mysql Sometimes, when querying information, you need to perform association query on the table itself , That is, a table is associated with itself , Use one table as multiple tables . Note that the table must be aliased during self association .
preparation
use mydb3;
create table t_sanguo
(
eid int primary key,
ename varchar(20),
manager_id int,
foreign key (manager_id) references t_sanguo(eid) # Add self association query
);
insert into t_sanguo values(1,' Liu Xie ',null);
insert into t_sanguo values(2,' Liu bei ',1);
insert into t_sanguo values(3,' Guan yu ',2);
insert into t_sanguo values(4,' Zhang Fei ',2);
insert into t_sanguo values(5,' Cao Cao ',1);
insert into t_sanguo values(6,' Xu Chu ',5);
insert into t_sanguo values(7,' Dianwei ',5);
insert into t_sanguo values(8,' king of Wu in the Three Kingdoms Era ',1);
insert into t_sanguo values(9,' Zhou Yu ',8);
insert into t_sanguo values(10,' Lu Su ',8);Open the reverse table to the model

part1
-- Make association query
-- Query the information of each person in the three countries and his superiors , Such as : Guan yu Liu bei
select a.ename,b.ename from t_sanguo a,t_sanguo b where a.manager_id = b.eid;
select a.ename,b.ename from t_sanguo a join t_sanguo b on a.manager_id = b.eid;
The operation results are as follows

part2
-- Query all tasks and superiors , Including Liu Xie
select a.ename,b.ename from t_sanguo a left join t_sanguo b on a.manager_id = b.eid;
part3
-- Query all people , The superior , Superior such as : Zhang Fei , Liu bei , Liu Xie
select a.ename,b.ename,c.ename
from t_sanguo a
left join t_sanguo b on a.manager_id = b.eid
left join t_sanguo c on b.manager_id = c.eid;
边栏推荐
- 有沒有sqlcdc監控多張錶 再關聯後 sink到另外一張錶的案例啊?全部在 mysql中操作
- The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
- A basic lintcode MySQL database problem
- Bigder:34/100 面试感觉挺好的,没有收到录取
- 3D drawing ()
- 【社区人物志】专访马龙伟:轮子不好用,那就自己造!
- Global and Chinese markets hitting traffic doors 2022-2028: Research Report on technology, participants, trends, market size and share
- Zero basic self-study STM32 wildfire review of GPIO use absolute address to operate GPIO
- Xshell 7 Student Edition
- Template_ Find the reverse pair of permutations_ Sort based on merge
猜你喜欢

PHP campus financial management system for computer graduation design

Easy to use js script

【MySQL 15】Could not increase number of max_open_files to more than 10000 (request: 65535)

The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower

Pat grade a 1033 to fill or not to fill

The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
![[Wu Enda machine learning] week5 programming assignment EX4 - neural network learning](/img/37/83953c24ec141667b304f9dac440f1.jpg)
[Wu Enda machine learning] week5 programming assignment EX4 - neural network learning

LeetCode 103. Binary tree zigzag level order transverse - Binary Tree Series Question 5

Reset nodejs of the system

The intelligent material transmission system of the 6th National Games of the Blue Bridge Cup
随机推荐
事故指标统计
Spark accumulator
大厂镜像库
MySQL (IV) - transactions
Template_ Find the reverse pair of permutations_ Sort based on merge
Jisuanke - t2063_ Missile interception
Template_ Quick sort_ Double pointer
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
How to generate rich text online
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
Adapter-a technology of adaptive pre training continuous learning
This time, thoroughly understand the deep copy
How to check the lock information in gbase 8C database?
Ue4- how to make a simple TPS role (II) - realize the basic movement of the role
[robot hand eye calibration] eye in hand
vs code保存时 出现两次格式化
RDD creation method of spark
[solution] add multiple directories in different parts of the same word document
HttpRunnerManager安装(三)-Linux下配置myql数据库&初始化数据
VIM usage guide