Skip to content
Advertisement

How do i select all in TABLE1 and join with matching MAX(id) from TABLE2?

I want to join TABLE1 with TABLE2, but only getting the highest id matching in TABLE2. TABLE1 will always only have 1 occurrence, while TABLE2 would have multiple occurrences, and i only want the row with the highest id.

Example:

TABLE1:

TABLE2

And this is what i want to get out:

I have tried with this:

And the output is:

But his gives me the row with the lowest id in TABLE2, and i want the row with the highest id. How can i do that?

Advertisement

Answer

One method puts the “maximum” condition in the ON clause:

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