MySQL: Limit a query to 10 rows where every index has 5 tags

toxicaid

New Member
I'd like to make a query where I can retrieve an interval of 10 rows with 5 tags per each one.I have \[code\]houses\[/code\] and \[code\]tags\[/code\] table, I know how to do it only for simple queries with a \[code\]SELECT\[/code\] using \[code\]LIMIT\[/code\] but how can I do it in this case?\[code\]table housesid house country1 Grunt Mansion us2 Hororo Suneku jp3 Casa Cattani it4 Sweet Home uk5 Heinzvaiter de6 F56X-5 us7 Swan Jong cn8 Drupnowevo ru9 Bambagiador br10 El Stanco estable houses_tagsid id_house id_tag1 1 12 1 23 1 34 1 45 2 16 2 27 2 38 2 4table tagsid tag1 minimal2 baroque3 cosy4 simple\[/code\]If a make a query like this to get the first 10 houses:\[code\]SELECT *FROM housesLEFT JOIN ( SELECT * FROM tags INNER JOIN houses_tags ON id_house = houses.id LIMIT 5) house_tagLIMIT 0, 10\[/code\]I get something like this:\[code\]query resultrow house country tag id_house id_tag1 Grunt Mansion us minimal 1 12 Grunt Mansion us baroque 1 23 Grunt Mansion us cosy 1 34 Grunt Mansion us simple 1 45 Hororo Suneku jp minimal 2 16 Hororo Suneku jp baroque 2 27 Hororo Suneku jp cosy 2 38 Hororo Suneku jp simple 2 49 Casa Cattani it NULL NULL NULL10 Sweet Home uk NULL NULL NULL\[/code\]My problem is I get only the first 10 rows cutting out the last \[code\]houses\[/code\] from the query because the \[code\]tags\[/code\] of the first ones occupy all the rowsCan I write a query where I can retrieve the first 10 houses and 5 tag per each one?\[code\]query resultrow house country tag id_house id_tag1 Grunt Mansion us minimal 1 12 Grunt Mansion us baroque 1 23 Grunt Mansion us cosy 1 34 Grunt Mansion us simple 1 45 Hororo Suneku jp minimal 2 16 Hororo Suneku jp baroque 2 27 Hororo Suneku jp cosy 2 38 Hororo Suneku jp simple 2 49 Casa Cattani it NULL NULL NULL10 Sweet Home uk NULL NULL NULL11 Heinzvaiter de NULL NULL NULL12 F56X-5 us NULL NULL NULL13 Swan Jong cn NULL NULL NULL14 Drupnowevo ru NULL NULL NULL15 Bambagiador br NULL NULL NULL16 El Stanco es NULL NULL NULL\[/code\]At the end I should need a result I display like this example:\[code\]Mansions TagsGrunt Mansion minimal, baroque, cosy, simpleHororo Suneku minimal, baroque, cosy, simpleCasa Cattani -Sweet Home -Heinzvaiter -F56X-5 -Swan Jong -Drupnowevo -Bambagiador -El Stanco -pages 1 | 2 | 3\[/code\]can I do it?
 
Back
Top