Mysql
 sql >> Base de Dados >  >> RDS >> Mysql

Consulta de resultado diferente ao usar mysql e mariadb


Você pode tentar as consultas abaixo, que fazem o trabalho de obter a última postagem de cada livro
select
b.id,
b.name,
p.content,
p.published_date
from book b 
join post p on p.book_id = b.id
left join post p1 on p1.book_id = p.book_id and p1.published_date > p.published_date
where p1.id is null;

OU
select 
b.id,
b.name,
p.content,
p.published_date
from book b 
join post p on p.book_id = b.id
where not exists(
  select 1 from post p1 
  where p.book_id = p1.book_id
  and p1.published_date > p.published_date
)

DEMO