当前位置:网站首页>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;
边栏推荐
- Guys, I tested three threads to write to three MySQL tables at the same time. Each thread writes 100000 pieces of data respectively, using F
- [loss functions of L1, L2 and smooth L1]
- How did the situation that NFT trading market mainly uses eth standard for trading come into being?
- [yolov5.yaml parsing]
- Pytorch softmax regression
- Redis集群的重定向
- iTOP-3568开发板NPU使用安装RKNN Toolkit Lite2
- C#实现WinForm DataGridView控件支持叠加数据绑定
- [LeetCode] Wildcard Matching 外卡匹配
- Is it difficult to apply for a job after graduation? "Hundreds of days and tens of millions" online recruitment activities to solve your problems
猜你喜欢
随机推荐
跨平台(32bit和64bit)的 printf 格式符 %lld 输出64位的解决方式
高校毕业求职难?“百日千万”网络招聘活动解决你的难题
The ninth Operation Committee meeting of dragon lizard community was successfully held
[deploy pytoch project through onnx using tensorrt]
Prevent browser backward operation
How to understand super browser? What scenarios can it be used in? What brands are there?
Redis集群的重定向
XML parsing
Crawler (9) - scrape framework (1) | scrape asynchronous web crawler framework
Pytorch softmax regression
Troubleshooting of high memory usage of redis in a production environment
An error is reported in the process of using gbase 8C database: 80000305, host IPS long to different cluster. How to solve it?
Cron expression (seven subexpressions)
POJ 3176 cow bowling (DP | memory search)
Harbor镜像仓库搭建
Acid transaction theory
【L1、L2、smooth L1三类损失函数】
Pytorch weight decay and dropout
【无标题】
Redis master-slave mode