Insert + into
select + from
update + 테이블 이름 + set + 변경할 내용 where 조건절
create table + 테이블 이름
create database + 데이터베이스 이름
drop table + 테이블 이름
drop database + 데이터베이스 이름
delete from + 테이블 이름 where 조건
TIP☝
Customer.name Orders.custid 등… Customer. / Orders. 을 매번 쓰기 힘들기때문에
From문 작성시 Customer C / Oders O 라고 작성하면 그 다음 문장부터 C 와 O로 대신해서 쓸 수 있다
예시)
select customer.name
from customer C, book B, orders O
where B.bookid = O.bookid
and C.custid = O.custid
and B.publisher = '대한미디어';
Q. 대한미디어에서 출판한 도서를 구매한 고객의 이름을 출력하세요 (서브쿼리+서브쿼리 문제)
/*대한미디어에서 출판한 도서를 구매한 고객의 이름을 출력하세요*/
select publisher, bookname from book where publisher like '대한미디어';
select custid from orders
where bookid in (select publisher from book where publisher like '대한미디어');
출력 : 안됨
--정답--
select customer.name from customer
where
custid in (select custid from orders where
bookid in (select bookid from book where publisher = '대한미디어'));
출력: 박지성
조인으로 작성
select customer.name from customer, book, orders
where book.bookid = orders.bookid
and customer.custid = orders.custid
and book.publisher = '대한미디어';
출력: 박지성