Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jul 2006
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Select first x -groups- of rows

    Hey,

    What I've got is 3 tables: news, category, newscategory. newscategory is just a linker table, so the relationship is like this:
    Code:
    [news.newsid] <--> [newscategory.newsid][newscategory.categoryid] <--> [category.categoryid]
    One entry in 'news' can be attached to many different categories via 'newscategory'.

    What I want to do is return the first X news posts from 'news', along with all the categories that each post belongs to. I can't figure out how to do this: using an INNER JOIN there will be multiple rows for each news post as there will be multiple categories associated with each post, (one row per category per post) but the LIMIT 0, X clause will apply to all the rows, which is not what I want...

  • #2
    Super Moderator guelphdad's Avatar
    Join Date
    Mar 2006
    Location
    St. Catharines, Ontario Canada
    Posts
    2,634
    Thanks
    4
    Thanked 148 Times in 139 Posts
    use GROUP_CONCAT on the categories then you will get a list of the categories that a story belongs to but GROUP BY newsid.

  • #3
    New Coder
    Join Date
    Jul 2006
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It worked perfectly! Brilliant! Thanks.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •