Use of inner join on, left join on, right join on

inner join (equivalent join) returns only the rows with equal join fields in the two tables

left join (left join) returns all records in the left table and records with the same join fields in the right table

right join (right join) returns including the right All records in the table and records in the left table with equal join fields


INNER JOIN syntax:
INNER JOIN Usage of joining two data tables:
SELECT * FROM table 1 INNER JOIN table 2 ON table 1. field number = table 2. field number

INNER The usage of JOIN to connect three data tables:
SELECT * FROM (table 1 INNER JOIN table 2 ON table 1. field number = table 2. field number) INNER JOIN table 3 ON table 1. field number = table 3. field number

INNER JOIN Usage of connecting four data tables:
SELECT * FROM ((table 1 INNER JOIN table 2 ON table 1. field number = table 2. field number) INNER JOIN table 3 ON table 1. field number = table 3. field number) INNER JOIN
table 4 ON Member. field number = table 4. field number

INNER JOIN usage of connecting five data tables:
SELECT * FROM (((table 1 INNER JOIN table 2 ON table 1. field number = table 2. field number) INNER JOIN table 3 ON table 1. field number = table 3. field number) INNER JOIN table 4 ON Member. field number = table 4. field number) INNER JOIN table 5 ON Member. field number = table 5. field number

(SELECT t6.f25 as 'ht',sum(t5.F05) ty from t6056 t5 inner join t6036 t6 on t5.F02 = t6.F01 where (t5.F10 = 'WS' and t6.F31< str_to_date('2016-12-01 00:00:00','%Y-%m-%d %H:%i:%s'))
or (t5.F10 = 'YS' AND t5.F09 >= str_to_date('2016-12-01 00:00:00','%Y-%m-%d %H:%i:%s') and t6.F31< str_to_date('2016-12-01 00:00:00','%Y-%m-%d %H:%i:%s')) and (t5.f08>= str_to_date('2015-10-01 00:00:00','%Y-%m-%d %H:%i:%s')
and t5.f08 < str_to_date(now(),'%Y-%m-%d %H:%i:%s'))
group by t6.f25 having F25 is not null order by ty desc limit 0,10)
union all
(SELECT t6.F52 as 'ht',sum(t5.F05) ty from t6056 t5 inner join t6036 t6 on t5.F02 = t6.F01 where ((t5.F10 = 'WS' and t6.F31< str_to_date('2016-12-01 00:00:00','%Y-%m-%d %H:%i:%s'))
or (t5.F10 = 'YS' AND t5.F09 >= str_to_date('2016-12-01 00:00:00','%Y-%m-%d %H:%i:%s') and t6.F31< str_to_date('2016-12-01 00:00:00','%Y-%m-%d %H:%i:%s'))
and (t5.f08>= str_to_date('2015-10-01 00:00:00','%Y-%m-%d %H:%i:%s') and t5.f08 < str_to_date(now(),'%Y-%m-%d %H:%i:%s'))
) and t6.F52 is not null and t6.F25 is null group by t6.F52
order by ty desc limit 0,10)
order by ty desc limit 0,10

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326939813&siteId=291194637