Q:

Limiting joined table to one result Mssql

I have two tables, one that stores general information and one that holds comments.
The structure is that a record in table one can have many corresponding results in table two.
However I am trying to write a query that pulls everything from table one and only the last comment from table 2.
For example, say there is a user in table one and they have 5 comments in table two, the query I want would pull the person from table one and only the last comment out of table two.
I have this query below however this will pull everything from table one which is what I want, but if there are multiple records for the record in table one it will bring them all in.
Quick example
Query results
ID  Field two  Field three  Field four     field out of table 2
1      Data       Data          Data           Comment 1
2      Data       Data          Data           Comment 1
2      Data       Data          Data           Comment 2
3      Data       Data          Data           Comment 1
4      Data       Data          Data           Comment 1
5      Data       Data          Data           Comment 1

As you can see as there are two comments for the record with ID 2 it is pulled in twice and what I want is just the last comment to be shown:
SELECT Qualitycontrol.ID, Qualitycontrol.MachineNo, Qualitycontrol.Description,    
    Qualitycontrol.CreatedTime, Qualitycontrol.ProductCode, Qualitycontrol.WorkOrder, 
    Qualitycontrol.Quantity, QualityControl_Comments.Comment
FROM Qualitycontrol 
LEFT OUTER JOIN QualityControl_Comments
           ON Qualitycontrol.ID = QualityControl_Comments.QCUID
WHERE (Qualitycontrol.CreatedTime 
        BETWEEN CAST(GETDATE() AS DATE) AND DATEADD(DAY, 1, CAST(GETDATE() AS DATE)))
ORDER BY Qualitycontrol.MachineNo

A:

Perform an OUTER APPLY instead of a LEFT JOIN:
SELECT Qualitycontrol.ID, Qualitycontrol.MachineNo, Qualitycontrol.Description,  
       Qualitycontrol.CreatedTime, Qualitycontrol.ProductCode, Qualitycontrol.WorkOrder, 
       Qualitycontrol.Quantity, Qc.Comment
FROM Qualitycontrol 
OUTER APPLY (
   SELECT TOP 5 Comment
   FROM QualityControl_Comments
   WHERE Qualitycontrol.ID = QCUID
   ORDER BY ... DESC -- whatever defines order in QualityControl_Comments
) AS Qc(Comment)                  
WHERE (Qualitycontrol.CreatedTime BETWEEN CAST(GETDATE() AS DATE) AND DATEADD(DAY, 1, CAST(GETDATE() AS DATE)))
ORDER BY Qualitycontrol.MachineNo

