Jump to content

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


aumbrother

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.