Hi,
Here is my current sql which outputs top 15 most emailed items. I am using SQL SERVER 2008, the sql will be in a stored procedure.
Code:
SELECT TOP 15
PS.poem_id,
PS.vote_average,
PS.vote_count,
P.poem_title,
P.name,
P.author_id,
P.bio,
P.comments,
P.poem,
C.main_category,
C.subcategories,
C.h1,
C.url
FROM poems AS P INNER JOIN
poem_stats AS PS ON PS.poem_id = P.poem_id INNER JOIN
category AS C ON P.category_fk = C.category_id
WHERE P.publish_ind='Y'
ORDER BY
PS.emailed DESC,
PS.vote_average DESC
I want instead to output the top 1 most emailed item from each of the 15 main categories. In other words I want each category represented. How do I do this?
Here is the sql to output the main categories
Code:
SELECT DISTINCT main_category FROM category
Thanks a lot!