当前位置:网站首页>Get to know MySQL connection query for the first time

Get to know MySQL connection query for the first time

2022-07-05 03:56:00 parallel

Classified by function :

Internal connection : Equivalent connection   :  The result is the intersection of multi table queries

                 Non equivalent connection

                 Self join

External connection : The left outer join : Left table is the main table

                 Right connection : The right table is the main one

                 Full outer join

Cross connect

sql92 standard : Only internal connections are supported

grammar :

SELECT  Query list  
FROM  surface 1, surface 2...
WHERE  Connection condition 
AND    Connection condition 
...
(AND  filter ) 
(GROUP BY  Clause 
 HAVING  filter 
 ORDER BY  Clause );

sql99 standard :

grammar :

Internal connection :inner( It can be omitted )

External connection : Left lateral :left (outer)

              Right outside :right (outer)

              Total external :full (outer)

cross :cross

SELECT  Query list 
FROM  surface 1
 Connection type  join  surface 2
on  How to connect 
....
(WHERE  filter 
GROUP BY  Clause 
HAVING  filter 
ORDER BY  Clause );

Such as :

SELECT COUNT(*)
FROM boy
INNER JOIN girl 
ON girl.boy_id = boy.id
WHERE boy.age > 25;

Be careful :

1. The query result of the external connection is all the records in the main table , If you match it from the right of the table , The value of the match , If not, display null

2. The left outer join and the right outer join can achieve the same effect by exchanging the order of the two tables

原网站

版权声明
本文为[parallel]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202140718135363.html