MYSQL-쿼리문 연습

박건태·2023년 7월 19일
0

MySQL

목록 보기
1/3

/ db 보여줘 /
show databases;

/ test라는 db를 사용할래 /
use test;

/ table보여줘 /
show tables;

/ product 보여줘 /
desc product;

/ product자세히 보여줘 /
select * from product;

#MYSQL에서는 ""와 ''가 큰 차이가 없으나, 다른 SQL DB는 ''를 주로 사용한다.
insert into product (id, name, description, price)
values(uuid(), '마우스', '정말 좋은 마우스입니다!!', 15000)
;
insert into product (id, name, description, price)
values(uuid(), '노트북', '최신 맥북!!', 20000)
;
insert into product (id, name, description, price)
values(uuid(), '셔츠', '깔끔한 셔츠입니다!!', 30000)
;

delete from product
where name = '셔츠'
;

update product
set price = 18000
where name = '마우스'
;

#==== 조인 ====

select * from product_sales_location psl;

insert into product_sales_location (id, address, addressDetail, lat, lng, meetingTime)
values (uuid(), '구로구', '구로 디지털 단지', 37.281732, 127.124345, '2023-01-10');

update product set productSalesLocationId = 'eab7c6ed-2615-11ee-a52e-3c5576ceb1ca'
where name = '마우스';

select p.id, name, price, address as '주소', addressDetail from product p, product_sales_location psl
where p.productSalesLocationId = psl.id;

#==== 추가기능 ====
update product set isSoldout = true where name = '노트북' and price = 20000;

update product set isSoldout = true where name = '노트북' or price = 20000;

#==== 주석 쉽게 다는 방법 ====
#update / delete에서는 노노!!
select *
from product
where 1 = 1
and name = '마우스'
and price = 5000
and isSoldout = false

1개의 댓글

comment-user-thumbnail
2023년 7월 19일

아주 잘 작성된 글이었습니다.

답글 달기