vb.net - SQL: Query 2 tables to get latest date for each record -
i have 2 tables want query customer , service
customer table
cnum lastname address phone comments 2 mckenzie main street 1234567898 none 3 stevenson south street 1225448844 none 4 adams north street 1234545454 none
service
incidentnum cnum servicedate status category lastupdated x1 2 02-21-2013 closed repair 02-21-2013 c2 2 05-12-2013 open installation 05-13-2013 d2 3 05-01-2013 closed repair 05-05-2013 f2 4 05-12-2013 open repair 05-12-2013
basically want display records latest update each customer record, regardless if status closed or open.
final:
cnum lastname address phone category last service 2 mckenzie main street 1234567898 installation 05-13-2013 3 stevenson south street 1225448844 repair 05-05-2013 4 adams north street 1234545454 repair 05-12-2013
im using oledb, project in vb. input appreciated. thank in advance!
can please try this?
select c.cnum, c.lastname, c.address, c.phone, s.category, s.servicedate customer c,service s c.cnum = s.cnum group c.cnum having s.lastupdated = max(s.lastupdated)
Comments
Post a Comment