Get top 5 records from Table A and for each, one result from Table B

  • delete pleaseeeee

    • This topic was modified 5 years, 5 months ago by rhapsap.
  • I just want the first record from TableB.fname returned for each of the 9 results in TableA and then move to the next record.

    SELECT A.Col1, A.Col2, BTop.Col1B, BTop.Col2B
    FROM A
    CROSS APPLY (SELECT TOP 5 Col1B, Col2B
    FROM B
    WHERE B.ForeignKey=A.PrimaryKey
    ORDER BY B.SomeColumn) BTop
  • Thank you but I'm only looking for TableA's top 5 results, and out of those five, the first cell from TableB where A's ID matches B's DIR value. This looks to be the opposite.

     

     

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply