PHP Top rated stories
I have 2 tables:
stories ID (int), CONTENT (text)
votes ID (int), TYPE (int, 1 or 0), ID_STORY (int)
How can I get the query to return the first top 10 stories ordered by votes (=1) desc.? I want to be able to print开发者_StackOverflow中文版 the top 10 stories content.
I've tried a lot of solution offered here for similar issues, but I couldn't manage to get it right...
SELECT *, count(votes) AS vcount
FROM stories s, votes v
WHERE s.id=v.id_story
AND v.type=1
GROUP BY v.id_story
ORDER BY vcount DESC
SELECT
storyid,content
FROM
stories
WHERE
storyid IN (
SELECT
storyid,count(votes) AS count
FROM
stories LEFT JOIN votes ON stories.storyid=votes.storyid
WHERE
type=1
GROUP BY votes.storyid
ORDER BY count DESC
)
精彩评论