- 가장 최근에 작성된 게시글 5개의 제목과 내용을 조회
select title, content
from post
order by created_at desc
limit 5;
- HTTP REST API "GET/ api/posts?orderBy=created_at&orderMethod=ASC"
select *
from post
order by created_at asc
- 게시글 내용에 "독서"라는 text가 포함된 게시글의 모든 내용(속성)을 조회
select *
from post
where content like '%독서%'
- 포스트 아이디 1, 2, 3번의 모든 댓글 조회
select *
from comment
where post_id in (2, 3, 4)
- alice 라는 사람이 단 모든 댓글 개수 조회
select count(*)
from comment
where user_id = (
select user_id
from user
where username = 'Alice'
);
--스칼라 쿼리?
-- sub query : sql query 안에 존재하는 sql query; 속성 값이 일치해야 함