Link to home
Start Free TrialLog in
Avatar of soozh
soozhFlag for Sweden

asked on

Select statement Pervaise.SQL

Hello,

I have  database table with rows that contain a patient id, sequence no and a value.  I want to return ONE row for each patient where the sequence no is highest.   The sequence no represents the visits and i want return data from the last visit.

See that data below and the returned dataset.
Pat id   seq    Value
A        1      23
A        2      17
A        3      25
B        1      17
C        1      24
C        2      16

Returns
A    3     25
B    1     17
C    2     16

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of saravanakg
saravanakg

try this query
select patid,max(seq),value from patient group by patid