I have a table which holds flight schedule data. Every schedule have an effective_from & effective_to date. I load this table from flat file which don’t provide me an effective_from and effective_to date. So at the time of loading I ask this information from user.
Suppose user gave from date as current date and to date as 31st March. Now on 1st March the user loads a new flight schedule and user give from date as current date and to date as 31st May.
If I query table for effective date between 1st March to 31st March the query returns me two records for each flight whereas I want only one record for each flight and this should be the latest record.
How do I do this? Should I handle this by query or while loading check and correct the data?
I developed this solution but looking for even better solution if possible.
Table Schedule { scheduleId, flightNumber, effective_from,effective_to } Data in Schedule table { 1, XYZ12, 01/01/2009, 31/03/2009 2, ABC12, 01/01/2009, 30/04/2009 }Now user loads another record 3, XYZ12, 01/03/2009, 31/05/2009
select scheduleId from Schedule where flightNumber = ‘XYZ12′ and (effective_from < ’01/03/2009′ and effective_to > ’01/03/2009′ or effective_from < ’31/05/2009′ and effective_to > ’31/05/2009’)
If the above query returns me any result that means its an overlap and I should throw an error to user.