I guess, U can use group by function while loading the data and then join the table. it will work like this:
1. get the id for max or min value and groupby id.. store this in temp table
2. after that make a left or right join to get the distinct records.
For more understanding please upload some sample data..