Hello all,
I am doing a data migration from an odbc data source, so it's not my design. I have two tables (well about 200 in total). Called 'PERSON' and 'TENANCY' for simplicity
'PERSON' [PrimaryKey - 'PERSON_REF'] contains details on the tenant and inherently 'TENANCY' [PrimaryKey - 'TENANCY_REF'] contains details on that persons tenancies which there are often more than one per person. These are related by the field 'PERSON_REF'
I am trying to write a query to pull ONLY the most recent tenancy details (defined by the 'START_DATE' field) over per person.
I have tried using SELECT DISTINCT/DISTINCTROW does this select the first record that it finds sequentially?
In this case should I sort the query by the 'START_DATE' field and use the SELECT DISTINCT statement.
Or is there a way in SQL to compare the 'START_DATE' of two adjacent records and return the most recent one?
I want to avoid processing the data using VB after the query has been run if possible.
Thanks for any help on this guys it's much appreciated.
Regards
I am doing a data migration from an odbc data source, so it's not my design. I have two tables (well about 200 in total). Called 'PERSON' and 'TENANCY' for simplicity
'PERSON' [PrimaryKey - 'PERSON_REF'] contains details on the tenant and inherently 'TENANCY' [PrimaryKey - 'TENANCY_REF'] contains details on that persons tenancies which there are often more than one per person. These are related by the field 'PERSON_REF'
I am trying to write a query to pull ONLY the most recent tenancy details (defined by the 'START_DATE' field) over per person.
I have tried using SELECT DISTINCT/DISTINCTROW does this select the first record that it finds sequentially?
In this case should I sort the query by the 'START_DATE' field and use the SELECT DISTINCT statement.
Or is there a way in SQL to compare the 'START_DATE' of two adjacent records and return the most recent one?
I want to avoid processing the data using VB after the query has been run if possible.
Thanks for any help on this guys it's much appreciated.
Regards