0

We have a database table with structure as such:

id (PK - identity, integer)
NPI (varchar)
lastname (varchar)
firstname (varchar)
city (varchar)
state (varchar)

The nature of the table is that some NPIs are in the table twice or N times.

We are trying to select the most recent NPI (that with the max id) given the other parameters.

I could do a

select * from NPI where id = (select max(id) from NPI where NPI = 'xxxx')

But this does not bring in the other info such as city/state.

I'd like to do something like this:

SELECT NPI from NPI where id = (select max(id) from npi where city = 'city')

but this only returns 1 row of course, the most recent NPI that is from that city.

How do I return all records from that city but only the most recent NPI?

4

0 回答 0