SELECT column1, (SELECT column2 FROM table2 WHERE condition)
FROM table1
WHERE condition;
SELECT a.column, b.column
FROM table1 a, (SELECT column1, column2 FROM table2 WHERE condition) b
WHERE condition;
SELECT column_names
FROM table_name
WHERE column_name = (SELECT column_name FROM table_name WHERE condition)
ORDER BY column_name;
# IN
SELECT column_names
FROM table_name
WHERE column_name IN (SELECT column_name FROM table_name WHERE condition)
ORDER BY column_name;
# EXISTS
SELECT column_names
FROM table_name
WHERE column_name EXISTS (SELECT column_name FROM table_name WHERE condition)
ORDER BY column_name;
# ANY
SELECT column_names
FROM table_name
WHERE column_name = ANY (SELECT column_name FROM table_name WHERE condition)
ORDER BY column_name;
# ALL
SELECT column_names
FROM table_name
WHERE column_name = ALL (SELECT column_name FROM table_name WHERE condition)
ORDER BY column_name;
SELECT column_names
FROM table_name a
WHERE (a.column1, a.column2,..) IN (SELECT b.column1, b.column2,.. FROM table_name b WHERE a.column_name = b.column_name)
ORDER BY column_name;
# 강동원과 성별, 소속사가 같은 연예인의 이름, 성별, 소속사를 조회
SELECT name, sex, agency
FROM celeb
WHERE (sex, agency) IN (SELECT sex, agency FROM celeb WHERE name = '강동원');
Reference
1) 제로베이스 강의자료