「サブクエリー+IN」、「LEFT JOIN」、「RIGHT JOIN」によりテーブルから同じ結果を抽出
出来ますが、INNER JOINでも同じ結果を抽出する事が出来ます。


SELECT PID,ID,NAME,START,END
FROM project WHERE project.id IN
(SELECT client.id FROM client);


select B.PID,B.ID,B.NAME,B.START,B.END from client A
LEFT JOIN project B using(ID) /* or: ON A.ID = B.ID */
WHERE B.NAME IS NOT NULL;


select B.PID,B.ID,B.NAME,B.START,B.END from client A
LEFT JOIN project B ON A.ID = B.ID /* or: using(ID) */
WHERE B.NAME IS NOT NULL;


select B.PID,B.ID,B.NAME,B.START,B.END from project B
RIGHT JOIN client A ON A.ID = B.ID /* or: using(ID) */
WHERE B.NAME IS NOT NULL;

INNER JOIN


select B.PID,B.ID,B.NAME,B.START,B.END from client A
INNER JOIN project B using(ID) /* or: ON A.ID = B.ID */
WHERE B.NAME IS NOT NULL;


select B.PID,B.ID,B.NAME,B.START,B.END from client A
INNER JOIN project B ON A.ID = B.ID /* or: using(ID) */
WHERE B.NAME IS NOT NULL;

inner_join_on

参考サイト
12.2.7.1. JOIN 構文

Comments are closed.

Post Navigation