Skip to content
Advertisement

MySQL SELECT from 2 tables get newest records

I have a problem with query. My database tabels:

FIRST TABLE

SECOND TABLE

For example like a Post and comments. I want newest comment in post.

Expected Output:

My query

OUTPUT:

I tried with MAX(date_add) but don’t work or I do it something wrong

Advertisement

Answer

You can use a subquery with MAX() aggregation for date_add column GROUPed BY notification_id within JOIN statements :

Demo

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement