없어진 기록 찾기

Updated:

JOIN류의 기본문제인것 같다.

JOIN을 아예 까먹어서 한번 보고 풀었다.

animal_ins 테이블과 animal_outs테이블을 합치는데, animal_outs의 animal_id가 없는 동시에, animal_ins의 animal_id가 있어야 하므로, left join명령어를 이용하고, where옵션을 이용해 체크를 해줬다. 마지막으로, animal_id에 의해 정렬이 되어야 하므로 아래와 같이 썼다.

by SQL

-- 코드를 입력하세요
SELECT A.ANIMAL_ID, A.NAME
from animal_outs A left join animal_ins B on A.animal_id = B.animal_id
where B.animal_id is null
order by A.animal_id

Leave a comment