当前位置:网站首页>MySQL advanced query
MySQL advanced query
2022-06-13 05:15:00 【strive_ one】
Join query operation
- When the columns of query results are from multiple tables , You need to join multiple tables into a large dataset , Select the appropriate column to return to .
mysql Three types of connection queries are supported , Namely :
- Internal connection query :
- The query result is the data that the two tables match
- Right connection query :
- The result of the query is the data matched by the two tables , Data unique to the right table , For data that does not exist in the left table, use null fill
- Left connection query :
- The result of the query is the data matched by the two tables , Data unique to the left table , Use the data that does not exist in the right table of teammates null fill
example :
- Now create a class table , A student watch :
create table classes(
id int unsigned primary key auto_increment not null,
name varchar(20) default '',
isdelete bit default 0
);
create table students(
id int unsigned primary key auto_increment not null,
name varchar(20) default '',
age tinyint unsigned default 0,
height decimal(5,2), -- Maximum 5 Digit number , Two decimal places
gender enum(' male ',' Woman ',' Simon? ',' A secret '),
cls_id int unsigned default 0,
isdelete bit default 0
);
- Insert data for the table
insert into classes values
(1,"python1", 0),
(2,"python2",0),
(3,"python3",0),
(4,"python4",0),
(6,"python5", 1);
insert into students values
(0,' Wei Shao ',18,180.00,2,1,0),
(0,' Little moon ',18,180.00,2,2,1),
(0,' peng ',29,185.00,1,1,0),
(0,' Lau Andy ',59,175.00,1,2,1),
(0,' lotus ',38,160.00,2,1,0),
(0,' feng ',28,150.00,4,2,1),
(0,' Joey wong ',18,172.00,2,1,1),
(0,' Jay Chou ',36,NULL,1,1,0),
(0,' Cheng Kun ',27,181.00,1,2,0),
(0,' Liu Yifei ',25,166.00,2,2,0),
(0,' Venus ',33,162.00,3,3,1),
(0,' Jingxiang ',12,180.00,2,4,0),
(0,' Zhou Jie ',34,176.00,2,5,0);
Link query
Internal connection query :inner join … on …
- on Followed by the conditions of the connection query .
- Use the inner link to query the class table and the student table
- Link query
- Query the class name and the class name of the student
- Student name : stay students surface
- Class name : stay classes surface
select students.name,classes.name from students inner join classes on students.cls_id = classes.id;
Left connection query :left join on
- Left join queries have master tables and slave tables
- left The previous main table ,left The following is the slave table
- All the data in the main table will be displayed ( Whether the connection condition is satisfied or not, it will display )
select s.name,c.name from students as s left join classes as c on s.cls_id = c.id;
Right link query :right join on
- Right connection query :right The preceding is the slave table ,right The following is the main table
select s.name,c.name from students as s right join classes as c on s.cls_id = c.id;
Extended learning : Show all the students in the class
- The first method of inner connection :
select c.name,group_concat(s.name) from students as s,classes as c where s.cls_id = c.id group by c.name;
- The second method of inner connection :
select c.name,group_concat(s.name) from students as s inner join classes as c on s.cls_id = c.id group by c.name;
- Practice of left connection :
select c.name,group_concat(s.name) from students as s left join classes as c on s.cls_id = c.id group by c.name;
- The practice of right connection :
select c.name,group_concat(s.name) from students as s right join classes as c on s.cls_id = c.id group by c.name;
Two shorthand modes of inner connection
- join on
select s.name, c.name from students as s join classes as c on s.cls_id = c.id;
- The second shorthand :cross join on
select s.name, c.name from students as s cross join classes as c on s.cls_id = c.id;
边栏推荐
- Chapter 13 abstraction: address space
- Chapter 2 process management
- Enhanced for loop
- Recursion and recursion
- Advanced C language - Section 1 - data storage
- C language learning log 2.19
- lookup
- QT brushes and brushes
- Pycharm错误解决:Process finished with exit code -1073741819 (0xC0000005)
- QT interface rendering style
猜你喜欢

QT interface rendering style

Simple SR: best buddy Gans for highly detailed image super resolution

MySQL8.0.13安装教程(有图)

Gradient descent, learning rate

Time display of the 12th Blue Bridge Cup

BM1Z002FJ-EVK-001开机测评

Understanding inode

Reductive elimination

QT direction key to move focus

C language learning log 10.19
随机推荐
Jeffery0207 blog navigation
【多线程】线程池核心类-ThreadPoolExecutor
Sampo Lock
C language learning log 10.8
Clause 33: decltype is used for auto & type formal parameters, with std:: forward
Opencv image storage and reading
Listiterator list iterator
C language learning log 10.19
Sub paragraph of Chapter 16
C language learning log 2.19
Modification and analysis of libcoap source code by Hongmeng device discovery module
QT signal is automatically associated with the slot
安装harbor(在线|离线)
metaRTC4.0稳定版发布
Bomb disposal cat
17.6 unique_lock详解
Simple sr: Best Buddy Gans for highly detailed image super resolution Paper Analysis
Simple SR: best buddy Gans for highly detailed image super resolution
C language learning log 12.5
Clause 26: avoid overloading universal reference types