我有两张 table :
表1:ID,PersonCode,名称,
表2:ID,Table1ID,Location,ServiceDate
我有一个查询将表1连接到table1.ID = table2.Table1ID,其中PersonCode ='XYZ'
我想要做的是返回Table1.PersonCode,Table1.Name,Table2.Location,Table2.ServiceDate,我不想要所有行,在表2中我只对每个位置具有最新ServiceDate的行感兴趣 . 我该怎么做呢?
4 回答
像这样的东西:
使用MAX(ServiceDate)
尝试:
我会使用
INNER JOIN
并选择第一条记录,根据Table2.ServiceDate以反向时间顺序排序记录 .