1. inner join(等值连接) 只返回两个表中联结字段相等的行
① 2个表进行查询
SELECT
t.tab1,
t.tab2,p.tab1
FROM
表1 AS t
INNER JOIN 表2 AS p
ON t.tab1 = p.tab1
GROUP BY t.tab2
②3个表进行查询
SELECT
t.tab1,
t.tab2,p.tab1
FROM
(
表1 AS a
INNER JOIN 表2 AS p
ON a.tab1 = p.tab1
)
INNER JOIN 表3 AS t
ON a.tab1 = t.tab1
GROUP BY t.tab2
③ 4个表进行查询
SELECT
t.tab1,
t.tab2,a.tab1
FROM
(
(
表1 AS a
INNER JOIN 表2 AS p
ON a.tab1 = p.tab1
)
INNER JOIN 表3 AS c
ON a.tab1 = c.tab1
)
INNER JOIN 表4 AS t
ON a.tab1 = t.tab1
GROUP BY t.tab2
④5个表进行查询
SELECT
t.tab1,
t.tab2,a.tab1
FROM
(
(
(
表1 AS a
INNER JOIN 表2 AS p
ON a.tab1 = p.tab1
)
INNER JOIN 表3 AS c
ON a.tab1 = c.tab1
)
INNER JOIN 表4 AS d
ON a.tab1 = d.tab1
)
INNER JOIN 表5 AS t
ON a.tab1 = t.tab1
GROUP BY t.tab2
⑤6个表进行查询...
多个表嵌套, 以此类推......
left join(左联接) 返回包括左表中的所有记录和右表中联结字段相等的记录
right join(右联接) 返回包括右表中的所有记录和左表中联结字段相等的记录
注:left join 、right join 和 inner join 一样嵌套即可, 不做举例~~