say i got a table like this :
cat_id, name,parent. with rows
1,"Shops",0
2,"Fashion",1
is there a way to create a query that would produce me the following
result? 2,"Shops / Fashion"
|
|
0
|
|
|
|
Reply
|
M
|
3/7/2008 12:46:33 PM |
|
On 7 Mar, 12:46, "M. K." <dilb...@i-wanna.live-spam-free.volny.cz>
wrote:
> say i got a table like this :
> cat_id, name,parent. with rows
> 1,"Shops",0
> 2,"Fashion",1
>
> is there a way to create a query that would produce me the following
> result? 2,"Shops / Fashion"
Something like:
SELECT CONCAT(t2.name,' / ',t1.name) FROM a_table t1
LEFT JOIN a_table t2 ON t1.parent = t2.cat_id
WHERE t1.cat_id = 2;
|
|
0
|
|
|
|
Reply
|
strawberry
|
3/7/2008 5:03:13 PM
|
|
On Fri, 07 Mar 2008 18:03:13 +0100, strawberry <zac.carey@gmail.com> wro=
te:
> On 7 Mar, 12:46, "M. K." <dilb...@i-wanna.live-spam-free.volny.cz>
> wrote:
>> say i got a table like this :
>> cat_id, name,parent. with rows
>> 1,"Shops",0
>> 2,"Fashion",1
>>
>> is there a way to create a query that would produce me the following
>> result? 2,"Shops / Fashion"
>
> Something like:
>
> SELECT CONCAT(t2.name,' / ',t1.name) FROM a_table t1
> LEFT JOIN a_table t2 ON t1.parent =3D t2.cat_id
> WHERE t1.cat_id =3D 2;
Indeed, with a join for every possible level in hierarchy (in which case=
=
is CONCAT_WS() is more appropriate, because one could as easily concat a=
=
7th level node as easily as a 2th level node without having problems wit=
h =
an 'overhead' of '/'s).
If the level should be / is desired to be unlimited, and the select's ar=
e =
much more abundant then alterations, the nested set model could be a =
solution. Harder on the inserts/updates (in hierarchy/position)/deletes,=
=
easier on the selects. See: =
<http://dev.mysql.com/tech-resources/articles/hierarchical-data.html>
-- =
Rik Wasmus
|
|
0
|
|
|
|
Reply
|
Rik
|
3/8/2008 1:42:36 AM
|
|
|
2 Replies
215 Views
(page loaded in 0.032 seconds)
Similiar Articles: group_cat question - comp.databases.mysqlsay i got a table like this : cat_id, name,parent. with rows 1,"Shops",0 2,"Fashion",1 is there a way to create a query that would produce me the fol... DSL splitter technical question - comp.dcom.xdslgroup_cat question - comp.databases.mysql Have pots splitter filter and questions - comp.dcom.xdsl ... DSL splitter technical question - comp.dcom.xdsl | Computer Group ... cat 5 Jack-to-jack pin-out - comp.home.automationgroup_cat question - comp.databases.mysql DSL splitter technical question - comp.dcom.xdsl | Computer Group cat 5 Jack-to-jack pin-out - comp.home.automation Have pots ... group_cat question - comp.databases.mysql | Computer Groupsay i got a table like this : cat_id, name,parent. with rows 1,"Shops",0 2,"Fashion",1 is there a way to create a query that would produce me the fol... Question For the Pets Group: Cat Fur Changing Color - Democratic ...I have a question that I hope one of you might be able to help me with. I have two beautiful kittens (brothers) who I adopted last summer from a local shelter. 7/26/2012 11:48:14 AM
|