Skip to content
Advertisement

How do I select rows that are not recent and are different from the last entry?

How do I select rows that are not recent and are different from the last entry? We recognize the differences by context field.

My example DB:

I would like to retrieve from try table rows with id: 4, 7, 8 and 11.

I tried the following:

But I have got the following error:

ERROR 1242 (21000) at line 120: Subquery returns more than 1 row

I don’t know how to deal with it. Maybe there is a solution other than subqueries?

Advertisement

Answer

Solution for your problem: (For MySQL 5.7)

db fiddle link

Solution for your problem: (For MySQL 8.0+)

dbfiddle link

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