LEFT JOIN, RIGHT JOIN, INNER JOIN, CROSS JOINで同じ結果を表示する。

LEFT JOIN

SELECT
p.pid AS `Project ID`,
p.name AS `Project Name`,
c.id AS `Client No`,
c.name AS `Client Name`
FROM project AS p
LEFT JOIN client AS c
USING (id) /* or: ON p.id = c.id */
WHERE c.name IS NOT NULL
;

left_join_review

RIGHT JOIN

SELECT
p.pid AS `Project ID`,
p.name AS `Project Name`,
c.id AS `Client No`,
c.name AS `Client Name`
FROM client AS c
RIGHT JOIN project AS p
USING (id) /* or: ON c.id = p.id */
WHERE c.name IS NOT NULL
;

right_join_review1

INNER JOIN

SELECT
p.pid AS `Project ID`,
p.name AS `Project Name`,
c.id AS `Client No`,
c.name AS `Client Name`
FROM project AS p
INNER JOIN client AS c
USING (id) /* or: ON p.id = c.id */
WHERE c.name IS NOT NULL
;

inner_join_review

CROSS JOIN

SELECT
p.pid AS `Project ID`,
p.name AS `Project Name`,
c.id AS `Client No`,
c.name AS `Client Name`
FROM project AS p
CROSS JOIN client AS c
USING (id) /* or: ON p.id = c.id */
WHERE c.name IS NOT NULL
;

cross_join_review

Comments are closed.

Post Navigation