Jump to content

Archived

This topic is now archived and is closed to further replies.

aumbrother

Is there a way to limit number of records per join?

Recommended Posts

Here is a tough one for you.

Say, I have a table "categories" and a table "topics".
Each category has thousands of topics in it.
I want to write a join query that would display all categories with 10 top rated titles next to it.

Here is what I have so far:

[color=blue][b]SELECT[/b] c.title,t.title,[b]COUNT[/b](t.id) [b]AS[/b] topic_count
[b]FROM[/b] category [b]AS[/b] c
[b]LEFT JOIN ON[/b] t.category_id = c.id
[b]GROUP BY[/b] c.id
[b]ORDER BY[/b] topic_count [b]DESC[/b][/color]

How do I modify this query so that it only gives me up to 10 topics per category?

Thanks in advance

Share this post


Link to post
Share on other sites
You'd probably need to JOIN in a dervied table.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.