The code below returns all records :-
SELECT b.BROKERAGE_NAME, q.VAL_DATE
FROM TBLQUOTESNEW q LEFT JOIN TBLBROKERAGESNEW b ON q.BROKERAGE_ID = b.ID
WHERE q.VAL_DATE Is Not Null
Is it possible to have the top 5 records for each BROKERAGE_NAME
returned, where VAL_DATE
is descending?
Included
Brokerage A 02/10/2017
Brokerage A 02/10/2017
Brokerage A 02/10/2017
Brokerage A 02/10/2017
Brokerage A 01/10/2017
Brokerage B 06/06/2016
Excluded (as not in top 5)
Brokerage A 30/09/2017