- 풀어보기 - DB입장에서 보기
-- 2. 이메일 중복체크
-- 기존 가입되어 있지 않은 이메일로 가입하려고 한다면
select member_email from member_table
where member_email = 'member_email7'; -- 멤버 컬럼에 없음
-- 기존 가입된 이메일로 가입하려고 한다면
select member_email from member_table
where member_email = 'member_email0'; -- 멤버 컬럼에 있음
-- 6. 회원정보 수정화면 요청
select * from member_table
where member_email = 'member_email3'; -- 특정 회원의 정보를 가져오고
-- 7. 회원정보 수정 처리(비밀번호 변경)
update member_table set member_password = '9999' where di = 5; -- 업데이트
DB입장에서 보면 java와 많이 다른데 DB에서는 정보를 받고 제약 조건에 걸리지만 않는다면 저장하기 때문이다
DB에서는 가공이나 정보 수정과 같은것이 이루어지지 않기 때문에 java와 차이가 있다
-- 2번 회원이 파일있는 자유게시판 글 2개 작성
insert into board_file_table ( original_file_name , stored_file_name , board_id)
values('륑냐흠' , '45747444릥냐흠' , 7);
insert into board_table
(board_title , board_writer , board_contents , member_id , category_id , board_file_attached)
values('륑냐흠' , '타우린' , '제곧내' , 7 , 1 , 5);
insert into board_file_table ( original_file_name , stored_file_name , board_id)
values('얍엽욥' , '45747444얍' , 7);
insert into board_table
(board_title , board_writer , board_contents , member_id , category_id , board_file_attached)
values('얍엽욥' , '타우린' , '제곧내' , 7 , 1 , 5);
-- 2.4 목록 조회시 카테고리 이름도 함께 나오게 조회
select b.* , c.category_name
from board_table b , category_table c
where b.category_id = c.id order by b.id asc;
DB의 입장에서 보면 파일도 올라가고 게시글도 작성되어야 한다 (2가지의 쿼리가 필요하다)
단, 어떤 게시글에 올라간 파일인지 알아야하기 때문에 fk받는 id번호가 있어야한다.
-- 3. 댓글 좋아요
-- 3.1. 1번 회원이 2번 회원이 작성한 댓글에 좋아요 클릭
-- 좋아요 하기 전 체크
select id from good_table where comment_id=2 and member_id =1;
-- 좋아요 한적이 없다면 좋아요
insert into good_table(comment_id , member_id)
values(2 , 1);
-- 좋아요 한적이 있다면 좋아요 취소
delete from good_table where id =1;
-- 4. 댓글 조회시 좋아요 갯수도 함께 조회
select c.* , count(g.comment_id) as '좋아요' from comment_table c ,good_table g
where c.id = g.comment_id
group by id ;
- 페이징_limit
-- 7.1. 첫번째 페이지
select * from board_table order by id desc limit 0,3;
-- 7.2. 두번째 페이지
select * from board_table order by id desc limit 3,3;
-- 7.3. 세번째 페이지
select * from board_table order by id desc limit 6,3;
-- 8.3 검색결과 페이징 처리
select * from board_table
where board_contents = '제곧내'
order by board_created_time
desc limit 0,3;
contents가 제곧내인 기준으로 검색하여 작성 시간을 기준으로 내림차순
페이징으로 0(0+1)번째 부터 3개를 출력
페이징 할 때 시작수부터 출력해줄 행의 갯수를 지정하는데
앞열은 java의 배열과 마찬가지로 0부터 인덱스 번호가 새로 붙는다
그렇기 때문에 3,3이라고 한다면 3+1 인 4번째부터 3개를 출력해준다