오늘 나는 (TIL)

[TIL 240627] union, update, insert, delete, multiple_join

thebuck104 2024. 6. 27. 20:02

오늘은 SQL 라이브세션 마지막차

 

아래와 같은 것들을 학습했다.

 


1. union

예시)

table a union table b

select aa from bb
union 
select cc from dd

 

두 테이블의 컬럼 순서가 같고, 형식이 같아야함

union, union all의 결과는 두 테이블의 수직 결합이고

 

union - 중복을 제거
union all - 중복을 제거 안하고 모두 표기해준다

 

2. update

예시)

update ~ set ~ where

update table set null where column = ""

update table 
set case 
when ~ then ~ 
end

 

 

3. insert

예시)

# 원하는 컬럼에만
insert into table (col_1,col_2) values(a,b)

# 컬럼 수 맞춰서
insert into table values(a,b,c,d,e)

 

4. delete

예시)

delete from table 
where a != b

 

 

5. Multiple Join

예시)

SELECT 
FROM table_abc
JOIN table_a ON a = b
JOIN table_c ON b = c
WHERE 
ORDER BY

 

테이블 A와 테이블 C의 정보를 모두 갖고 있는 테이블 ABC는

위 처럼 조인을 두번 해서 여러 정보를 가져올 수 있다.

 


 

MySQL에서 Join 은 아래와 같이 작동한다.