0

I have two tables: tableA and tableB. One row in tableA has many records in tableB.

How do I write a select query to join both tables and return only the latest record from tableB when joining.

Ex: TableA

ID   NAME
--
ABC  JOHN

TableB

ID   Role LastUpdateDate
--
ABC  M    07/07/15
ABC  C    03/04/14
ABC  S    03/04/17

I want to retrieve ABC, JOHN, S, 03/04/17

mustaccio
  • 18,234
  • 16
  • 48
  • 57
Ani
  • 328
  • 1
  • 3
  • 17

1 Answers1

0

you can try something like this.

select tableB.ID,tableB.Role, Max(tableB.LastUpdateDate)
from tableA inner join tableB
on tableA.ID = tableB.ID
group by tableB.ID,tableB.Role;
Andy
  • 49,085
  • 60
  • 166
  • 233
viggy28
  • 760
  • 1
  • 10
  • 21