I'm just wondering if the following two sql statements have any performance differences or if they are essentially the same:
To select the last record, the spouse of the person from the table spouse(person_id, spouse_id, marriage_date).
select *
from spouse
where (person_id, marriage_date) in ( select person_id, max(marriage_date)
from spouse
group by person_id
)
select *
from spouse s1
where marriage_date = ( select max(marriage_date)
from spouse s2
where s1.person_id = s2.person_id
)
This is a common reporting requirement, for example, recent employee work, higher education, etc. etc. I would like to know if you prefer the above statements one by one and why, or if there are others better (in terms of performance / readability) to fulfill these requirements for the most recent / maximum.
source
share