当前位置:网站首页>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;
边栏推荐
- 全网最全的新型数据库、多维表格平台盘点 Notion、FlowUs、Airtable、SeaTable、维格表 Vika、飞书多维表格、黑帕云、织信 Informat、语雀
- 【L1、L2、smooth L1三类损失函数】
- [leetcode] wild card matching
- Project summary notes series wstax kt session2 code analysis
- How to get a token from tokenstream based on Lucene 3.5.0
- MySQL statistical skills: on duplicate key update usage
- Cdga | six principles that data governance has to adhere to
- Acid transaction theory
- 11.(地图数据篇)OSM数据如何下载使用
- 【上采样方式-OpenCV插值】
猜你喜欢

CDGA|数据治理不得不坚持的六个原则

如何让你的产品越贵越好卖

多表操作-自关联查询

Redis master-slave mode

无线WIFI学习型8路发射遥控模块

pytorch训练进程被中断了

【pytorch 修改预训练模型:实测加载预训练模型与模型随机初始化差别不大】

Is it difficult to apply for a job after graduation? "Hundreds of days and tens of millions" online recruitment activities to solve your problems

XML parsing

Yolov 5 Target Detection Neural Network - Loss Function Calculation Principle
随机推荐
[upsampling method opencv interpolation]
Cron expression (seven subexpressions)
7.2 daily study 4
7 themes and 9 technology masters! Dragon Dragon lecture hall hard core live broadcast preview in July, see you tomorrow
Idea set the number of open file windows
Redis集群(主从)脑裂及解决方案
Mysql统计技巧:ON DUPLICATE KEY UPDATE用法
C # implements WinForm DataGridView control to support overlay data binding
How to get a token from tokenstream based on Lucene 3.5.0
【TFLite, ONNX, CoreML, TensorRT Export】
阻止浏览器后退操作
codeforces每日5题(均1700)-第五天
Question and answer 45: application of performance probe monitoring principle node JS probe
Principle of redis cluster mode
【云原生 | Kubernetes篇】Ingress案例实战(十三)
XML解析
Crawler (9) - scrape framework (1) | scrape asynchronous web crawler framework
2048游戏逻辑
【yolov3损失函数】
【无标题】

