-1

I have a record set as below:

company_id      po_date     po_number       supplier_company_id

1             01/01/2017        1000          20
1             02/01/2017        1001          20
1             03/01/2017        1002          20
2             01/02/2017        1005          30
2             02/02/2017        1006          30
2             03/02/2017        1007          30

and I want to return the records for the latest dates per company_id

company_id      po_date     po_number       supplier_company_id

1              03/01/2017       1002        20
2              03/02/2017       1007        30

1 Answers1

1

use this

select * from 
(select t.*,row_number() over (partition by company_id order by po_date desc) rn
from your_table t)
where rn=1
Utsav
  • 7,914
  • 2
  • 17
  • 38
  • I get an error for sql command not properly ended. – Ankita Tripathi Mar 31 '17 at 10:30
  • Check the answer which is tagged with your question. And try to modify the query. I cannot create the table but as per query, I don't find why it will give you this error. – Utsav Mar 31 '17 at 10:32