Here is my situation:
I have one table that contains a list of drugs sold containing the NDC (an identifier), quantity sold, and whether the drug is a brand name or
This would get you each one on a separate line:
SELECT
`cl`.`ndc`,
`cl`.`rx_num`
FROM `claims_list` AS `cl`
WHERE `cl`.`ndc` IN
(
SELECT `dl`.`ndc` FROM `drug_list` AS `dl`
WHERE `dl`.`type` = 'Generic'
ORDER BY `dl`.`qty` DESC
LIMIT 50
)
ORDER BY `cl`.`date` DESC
LIMIT 4
Then run the results through a filter in the calling script to group them together.