I need to select the “bundle” entries from the table below but only if a bundle exists other wise select track 1 from each release. Each release has a unique “cat_no” which is why I need to use GROUP BY.
SELECT * FROM cds
WHERE genre='rock'
GROUP BY cat_no
ORDER BY ABS(track) DESC
LIMIT 0,3
This what I have tried but I am sometimes getting track 1 when there is a bundle for that release.
Table
genre cat_no track
rock 001 1
rock 001 2
rock 001 bundle
rock 002 1
rock 002 2
rock 002 bundle
rock 003 1
rock 003 2
Try to sort records before the grouping –