Вам просто нужно было присоединить таблицу posts
к вашему (немного сломанному, теперь исправленному) запросу:
SQL Fiddle
Настройка схемы MySQL 5.6 :
Create table posts(
post_id int,
post_creator_id int,
post_title varchar(100)
);
INSERT INTO posts VALUES (1, 100, 'Hello All');
INSERT INTO posts VALUES (2, 14,'Good morning');
INSERT INTO posts VALUES (3, 213, 'Lovely Day');
INSERT INTO posts VALUES (4, 55, 'Nice Title!');
create table comments(
comment_id int,
post_id int,
commenter_id int,
comment_text varchar(100),
date datetime
);
insert into comments values (8 , 1, 98, 'Hello world', '2018-04-27 12:02:22' );
insert into comments values (9 , 4, 123, 'Hi all', '2018-04-27 13:11:11' );
insert into comments values (10 , 4, 77, 'Looking good', '2018-04-27 13:20:17' );
insert into comments values (11 , 1, 101, 'Great idea', '2018-04-27 14:45:15' );
Запрос 1 :
select a.*, p.post_title, p.post_creator_id
from comments a
join (
select post_id, max(date) as date_entered
from comments
group by (post_id)
) b on a.post_id = b.post_id and a.date = b.date_entered
join posts p on p.post_id = b.post_id
Результаты
| comment_id | post_id | commenter_id | comment_text | date | post_title | post_creator_id |
|------------|---------|--------------|--------------|----------------------|-------------|-----------------|
| 11 | 1 | 101 | Great idea | 2018-04-27T14:45:15Z | Hello All | 100 |
| 10 | 4 | 77 | Looking good | 2018-04-27T13:20:17Z | Nice Title! | 55 |