Is it possible to return last row out of multiple based on row index? Here's what I'm trying to do:
I have a table, which I don't have administration over, with 4 interestingfields:
RecordCount - an auto incrementing primary key
CardNumber - integer
CompanyID - integer
AccessPriv - an string that varies constantly
There could be identical CardNumber's, but they must have differentCompanyId's. A data set might look like this:
RecordCount | CardNumber | CompanyID | AccessPriv
1 | 1 | 82 | all
2 | 2 | 82 | level 1
3 | 2 | 84 | all
4 | 1 | 82 | none
The table is transactional, so old records will not be flushed even thoughnew records contain the most current data (records 1 and 4 in this case). I'm wondering if there's a way to do a SQL SELECT query that, as it goesfrom the beginning to the end of the table, overwrites previous recordswhen later CardNumber's and CompanyID's match the previous records. So inthis case, the query would only return rows 2-4 because record 4'sCardNumber and CompanyID match record 1's.
I know this is possible with application logic, but is it possible with anSQL query?
Thanks. |