I have a table full of magazines, and need to extract the latest unique issue of each magazine.
Ive tried
SELECT DISTINCT
magazine
FROM
product p
INNER JOIN
(SELECT
title, MAX(onSale) AS Latest
FROM
product
GROUP BY magazine) groupedp
Which returns the distinct magazines , but not the rest of the data I require.
UPDATE:
schema
-id----onsale----magazine
1 1/12/12 Fishing Mag
2 1/11/12 Fishing Mag
3 12/03/11 Pencil Sharpening Monthly
4 1/02/10 Pencil Sharpening Monthly
5 16/04/09 Homes in the Sky
So the result I would like returned would be:
-id----onsale----magazine
1 1/12/12 Fishing Mag
3 12/03/11 Pencil Sharpening Monthly
5 16/04/09 Homes in the Sky
解决方案SELECT
p.*
FROM
product p
INNER JOIN
( SELECT
magazine, MAX(onSale) AS latest
FROM
product
GROUP BY
magazine
) AS groupedp
ON groupedp.magazine = p.magazine
AND groupedp.latest = p.onSale ;