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
  • 17,405
  • 14
  • 45
  • 53
Ani
  • 318
  • 1
  • 3
  • 16

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
  • 46,308
  • 56
  • 161
  • 219
viggy28
  • 622
  • 8
  • 20