...

View Full Version : Select first x -groups- of rows



FoxyForest
07-31-2006, 04:07 PM
Hey,

What I've got is 3 tables: news, category, newscategory. newscategory is just a linker table, so the relationship is like this:


[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...

guelphdad
07-31-2006, 04:52 PM
use GROUP_CONCAT on the categories then you will get a list of the categories that a story belongs to but GROUP BY newsid.

FoxyForest
07-31-2006, 05:22 PM
It worked perfectly! Brilliant! :D Thanks. :thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum