SQL query - Join that returns the first two records of joining table

后端 未结 8 1850
陌清茗
陌清茗 2021-02-02 03:50

I have two tables:

Patient

  • pkPatientId
  • FirstName
  • Surname

PatientStatus

  • pk
8条回答
  •  误落风尘
    2021-02-02 03:53

    I did not try but this could work;

    SELECT /*(your select columns here)*/, row_number() over(ORDER BY ps.fkPatientId, ps.StartDate) as rownumber FROM Patient p INNER JOIN PatientStatus ps ON p.pkPatientId = ps.fkPatientId
    where rownumber between 1 and 2
    

    if this did not work, see this link.

提交回复
热议问题