View Single Post

   
  #4 (permalink)  
Old 02-28-2008, 07:49 PM
Ted
 
Posts: n/a
Default Re: Is it possible to return last row out of multiple based on row index?

Thanks for the help David and Igor!

-Ted


On Sun, 16 Nov 2003 10:08:57 -0800, Igor Raytsin wrote:
>*You could try this:
>
>*SELECT *
>*FROM _table_ t1
>*INNER JOIN (
>*SELECT MAX(RecordCount) as LastRecordCount FROM _table_
>*GROUP BY CardNumber, CompanyID ) as t2 ON t1.RecordCount =
>*t2.LastRecordCount
>
>
>*Hope this helps.
>*Igor Raytsin
>
>
>*"Ted" <no@thanks.invalid>*wrote in messagenews:200311166112.081904@dev...
>*Here's what I'm trying to do:
>
>*I have a table, which I don't have administration over, with 4interesting
>*fields:
>*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 different
>*CompanyId'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 eventhough
>*new 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 goes
>*from 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's CardNumberand
>*CompanyID match record 1's.
>
>*I know this is possible with application logic, but is it possible withan
>*SQL query?
>
>*Thanks.



Reply With Quote