The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
||||
|
||||
grouping by for a query
is their a method at all to get it only select XX records from each group?
|
#2
|
||||
|
||||
/me thinks w00t
/me bumps the thread |
#3
|
||||
|
||||
I don't understand what you actually want to retrieve.
Can you give some example data and what you want to have returned? |
#4
|
|||
|
|||
What he wants is to retrieve all "groups" from a group table together with maximum 10 detailrows from a groupitems table for every group in 1 query.
Just a simple left join, except he wants to limit the number of rows from the second table. I don't know of any solution coded in 1 SQL (or to lazy to think about it ). Only a loop through the groups and then fetching max 10 items i can think of. |
#5
|
||||
|
||||
yeah my initial idea was gonna be a query per group but if you have 12 catergories that's like an additional 12 queries per page, not good.
Quote:
a table (catergories) catid title description 1 Automotive For groups referring to cars, bikes or such 2 Computers For groups referring to computers, whether hardwar... 3 Education For groups regarding learning, whether it be help ... 4 Entertainment For groups surrounding anything entertaining, visu... 5 Games For groups surrounding games you love, digital or ... 6 Health & Fitness For groups pertaining to well-being 7 Home & Families For groups regarding the home life 8 Lifestyles For groups surrounding lifestyles whether it be go... 9 Places & Travel For groups referring to towns, cities and holidays 10 Religion & Belief For groups surrounding christianity, islam, buddis... 11 Sports & Recreation For groups referring to sports, whether it be Foot... 12 Others For everything else now these are leftjoined to a groups table so it will display all groups that fall into each catergory, however i went to make it so it shows a maximum of ten records for each catid here's the code that pulls this data from the database PHP Code:
|
#6
|
||||
|
||||
Hmm, this is outside of my SQL knowledge but I have a feeling it can be done. Post your question up in the MySQL forums on sitepoint and rudy will help you out Just your question and db structure though, he's not a PHP programmer.
|
#7
|
||||
|
||||
thanks dean that worked out perfectly.
here's the code incase anyones interested [sql] SELECT grps.groupid, grps.title, grps.description, grps.catid, grps_catergories.title AS catname, grps.approved, grps.leaderid FROM grps_catergories INNER JOIN grps ON grps_catergories.catid = grps.catid AND grps.approved = 1 INNER JOIN grps AS G2 ON grps_catergories.catid = G2.catid AND G2.approved = 1 AND grps.title >= G2.title GROUP BY grps_catergories.title, grps.title, grps.description, grps.leaderid HAVING COUNT(*) <= 10 ORDER BY grps.title [/sql] |
Thread Tools | |
Display Modes | |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|