当前位置:网站首页>Multi table operation - Auto Association query
Multi table operation - Auto Association query
2022-07-05 11:47:00 【Soup key TJ】
Catalog
Basic concepts
- In the same table, the data is related , We can query this table as multiple tables
- This is achieved by taking different aliases for the table
Data preparation
- CREATE TABLE employee(
id INT PRIMARY KEY auto_increment, -- Employee number
NAME VARCHAR(20), -- Employee name
mgr INT, -- Superior number
salary DOUBLE -- Wages
); - -- Add data
- INSERT INTO employee VALUES (1001,' The Monkey King ',1005,9000.00),
- (1002,' Pig eight quit ',1005,8000.00),
- (1003,' The sand monk ',1005,8500.00),
- (1004,' Small white dragon ',1005,7900.00),
- (1005,' Tang's monk ',NULL,15000.00),
- (1006,' Wusong ',1009,7600.00),
- (1007,' Li Kui ',1009,7400.00),
- (1008,' Lin Chong ',1009,8100.00),
- (1009,' Song Jiang ',NULL,16000.00);
Example operation
- Check the names of all employees and their immediate superiors , Employees without superiors also need to inquire
- adopt mgr Can find the superior
- Then employees without superiors also need to query , This requires external connection query
-- Check the names of all employees and their immediate superiors , Employees without superiors also need to inquire -- Conditions :employee.mgr=employee.id SELECT e1.id, e1.name, e1.mgr, e2.id, e2.name FROM employee e1 LEFT OUTER JOIN employee e2 ON e1.mgr=e2.id;
边栏推荐
猜你喜欢
COMSOL -- establishment of geometric model -- establishment of two-dimensional graphics
Advanced technology management - what is the physical, mental and mental strength of managers
【Win11 多用户同时登录远程桌面配置方法】
Pytorch softmax regression
yolov5目標檢測神經網絡——損失函數計算原理
CDGA|数据治理不得不坚持的六个原则
Harbor image warehouse construction
【yolov5.yaml解析】
Reading notes of growth hacker
Riddle 1
随机推荐
Web API configuration custom route
Harbor镜像仓库搭建
POJ 3176 cow bowling (DP | memory search)
Open3d European clustering
Pytorch linear regression
【yolov3损失函数】
阻止浏览器后退操作
POJ 3176-Cow Bowling(DP||记忆化搜索)
Implementation of array hash function in PHP
COMSOL -- three-dimensional graphics random drawing -- rotation
13.(地图数据篇)百度坐标(BD09)、国测局坐标(火星坐标,GCJ02)、和WGS84坐标系之间的转换
Acid transaction theory
COMSOL -- establishment of 3D graphics
COMSOL -- 3D casual painting -- sweeping
Zcmu--1390: queue problem (1)
[yolov3 loss function]
11. (map data section) how to download and use OSM data
Crawler (9) - scrape framework (1) | scrape asynchronous web crawler framework
Go language learning notes - first acquaintance with go language
Ncp1342 chip substitute pn8213 65W gallium nitride charger scheme