• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 179
  • Last Modified:

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

0
soozh
Asked:
soozh
1 Solution
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
what about this
select t.*
  from yourtable t
 where t.seq = (Select max(i.seq) from yourtable i where i.patid = t.patid )

Open in new window

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

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now