SELECT 테이블1.칼럼명, 테이블2.칼럼명, ...
FROM 테이블1, 테이블2
WHERE 테이블1.칼럼명1 = 테이블2.칼럼명2;
=> WHERE 절에 JOIN 조건을 넣는다.
SELECT 테이블1.칼럼명, 테이블2.칼럼명, ...
FROM 테이블1
INNER JOIN 테이블2
ON 테이블1.칼럼명1 = 테이블2.칼럼명2;
=> ON 절에 JOIN 조건을 넣는다. (조건식)
SELECT PLAYER.PLAYER_NAME 선수명
, TEAM.TEAM_NAME 소속팀명
FROM PLAYER, TEAM
WHERE PLAYER.TEAM_ID = TEAM.TEAM_ID;
SELECT PLAYER.PLAYER_NAME 선수명
, TEAM.TEAM_NAME 소속팀명
FROM PLAYER
INNER JOIN TEAM
ON PLAYER.TEAM_ID = TEAM.TEAM_ID;
--WHERE조건을 이용한 JOIN
SELECT PLAYER.PLAYER_NAME
, PLAYER.BACK_NO
, PLAYER.TEAM_ID
, TEAM.TEAM_NAME
, TEAM.REGION_NAME
FROM PLAYER, TEAM
WHERE PLAYER.TEAM_ID = TEAM.TEAM_ID;
--ANSI JOIN
SELECT PLAYER.PLAYER_NAME
, PLAYER.BACK_NO
, PLAYER.TEAM_ID
, TEAM.TEAM_NAME
, TEAM.REGION_NAME
FROM PLAYER
INNER JOIN TEAM
ON PLAYER.TEAM_ID = TEAM.TEAM_ID;
--WHERE조건을 이용한 JOIN
SELECT A.PLAYER_NAME
, A.BACK_NO
, A.TEAM_ID
, B.TEAM_NAME
, B.REGION_NAME
FROM PLAYER A, TEAM B
WHERE A.TEAM_ID = B.TEAM_ID;
--ANSI JOIN
SELECT A.PLAYER_NAME
, A.BACK_NO
, A.TEAM_ID
, B.TEAM_NAME
, B.REGION_NAME
FROM PLAYER A
INNER JOIN TEAM B
ON A.TEAM_ID = B.TEAM_ID;
-- WHERE 조건 JOIN
SELECT A.PLAYER_NAME
, A.BACK_NO
, A.TEAM_ID
, B.TEAM_NAME
, B.REGION_NAME
FROM PLAYER A, TEAM B
WHERE A.TEAM_ID = B.TEAM_ID
AND A.POSITION = 'GK'
ORDER BY A.BACK_NO;
--ANSI
SELECT A.PLAYER_NAME
, A.BACK_NO
, A.TEAM_ID
, B.TEAM_NAME
, B.REGION_NAME
FROM PLAYER A
INNER JOIN TEAM B
ON A.TEAM_ID = B.TEAM_ID
WHERE A.POSITION = 'GK'
ORDER BY A.BACK_NO;
SELECT PLAYER.PLAYER_NAME -- 열명이 부적합 합니다. 발생
, A.BACK_NO
, A.TEAM_ID
, B.TEAM_NAME
, B.REGION_NAME
FROM PLAYER A
INNER JOIN TEAM B
ON A.TEAM_ID = B.TEAM_ID
WHERE A.POSITION = 'GK'
ORDER BY A.BACK_NO;
SELECT E.ENAME
, E.JOB
, E.SAL
, S.GRADE
FROM EMP E, SALGRADE S
WHERE E.SAL BETWEEN S.LOSAL AND S.HISAL;
SELECT E.ENAME 사원명
, E.SAL 급여
, S.GRADE 급여등급
FROM EMP E, SALGRADE S
WHERE E.SAL BETWEEN S.LOSAL AND S.HISAL;
-- WHERE JOIN
SELECT P.PLAYER_NAME 선수명
, P.POSITION 포지션
, T.REGION_NAME 연고지
, T.TEAM_NAME 팀명
, S.STADIUM_NAME 구장명
FROM PLAYER P, TEAM T, STADIUM S
WHERE P.TEAM_ID = T.TEAM_ID
AND T.STADIUM_ID = S.STADIUM_ID
ORDER BY 선수명;
-- ANSI
SELECT P.PLAYER_NAME 선수명
, P.POSITION 포지션
, T.REGION_NAME 연고지
, T.TEAM_NAME 팀명
, S.STADIUM_NAME 구장명
FROM PLAYER P
INNER JOIN TEAM T
ON P.TEAM_ID = T.TEAM_ID
INNER JOIN STADIUM S
ON T.STADIUM_ID = S.STADIUM_ID
ORDER BY 선수명;