Skip to content
Advertisement

SQL select the latest record on joined tables

I want to retrieve the property which an user paid a tax last.

have two tables person_properties and property_taxes

What I tried so far:

This gives me the person_id along the max year. But I actually need the property_id, the property which an user paid last.

If I replace pp.person_id by pp.property_id, I then get all properties, of course.. not grouped by person, which excludes an user that has more than one property.

Any little tweak that can help me get the desired result?

Advertisement

Answer

DISTINCT ON might do what you want?

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