talendguy talendguy - 1 year ago 142
SQL Question

SQL query last transactions

enter image description here

You can't see on the image but I have many till_id numbers. (1,2,3,4,5).

What I want to do is just showing the last "trans_num" without repeating the till_id.

For example:

till_id trans_num
1 14211
2 14333
3 14555

Answer Source

A typical way to do this is:

select t.*
from t
where t.trans_date = (select max(t2.trans_date)
                      from t t2 
                      where t2.till_id = t.till_id
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download