I have three tables: users, posts, and comments.
How do I SELECT the first three posts, each with their comment count and first three comments?
Example: SQL Fiddle
Goal is to build a table like the one below
- The first row of each post_id grouping is the post
- The comment_id is that post's comment count
- The next rows are the first three comments for that post
Expected output:
-- post_id comment_id user_id body created_at
-- 1 4 1 Hello. I'm Jane. August, 28 2016 14:12:01
-- 1 1 2 Nice post, Jane. August, 28 2016 14:12:01
-- 1 2 1 Thank you, John. August, 28 2016 14:12:01
-- 1 3 2 You're welcome. August, 28 2016 14:12:01
-- 2 2 1 This is post 2. August, 28 2016 14:12:01
-- 2 5 2 I like this. August, 28 2016 14:12:01
-- 2 6 1 Why, thank you. August, 28 2016 14:12:01
-- 3 0 1 This is post 3. August, 28 2016 14:12:01