March 4, 2009 at 5:05 am
I have a data as
ParentID ChildID
1 2
1 3
1 4
2 5
3 6
Please let me know the query which should give me data as
1 -- ParenID
2 --ChildID
1 --ParentID
2 --ChildID
1
4 "
2
5 "
3
6
Please give me solution for this.Thanks in advance.
March 4, 2009 at 5:16 am
try this code..
SELECT ParentId , '--Parentid' AS TypeId
FROM YouTable
UNION
SELECT ChildId , '--Childid' AS TypeId
FROM YourTable
March 4, 2009 at 5:21 am
steveb (3/4/2009)
try this code..
SELECT ParentId , '--Parentid' AS TypeId
FROM YouTable
UNION
SELECT ChildId , '--Childid' AS TypeId
FROM YourTable
Instead of UNION use UNION ALL because the UNION statement select only distinct values the UNION ALL select all values!
March 4, 2009 at 5:24 am
Dugi (3/4/2009)
steveb (3/4/2009)
try this code..
SELECT ParentId , '--Parentid' AS TypeId
FROM YouTable
UNION ALL
SELECT ChildId , '--Childid' AS TypeId
FROM YourTable
Instead of UNION use UNION ALL because the UNION statement select only distinct values the UNION ALL select all values!
good point !! thanks
March 4, 2009 at 5:28 am
steveb (3/4/2009)
good point !! thanks
As always all helps and alternative suggests are welcomed from each-other!
😉
March 4, 2009 at 9:11 pm
I am not getting the result as I want
MY data in the table is as
Node Child_Node
41454285
41454286
41454287
42454285
42454286
42454287
by the solution provided by you i am getting result as:-
Node TypeID
41--Parentid
41--Parentid
41--Parentid
42--Parentid
42--Parentid
42--Parentid
454285--Childid
454286--Childid
454287--Childid
454285--Childid
454286--Childid
454287--Childid
But I want result as Child should be shown immediate after the parent as shown below.
Node TypeID
41--Parentid
454285--Childid
41--Parentid
454286--Childid
41--Parentid
454287--Childid
42--Parentid
454285--Childid
42--Parentid
454286--Childid
42--Parentid
454287--Childid
OR result can be like this also.
Node TypeID
41--Parentid
454285--Childid
454286--Childid
454287--Childid
42--Parentid
454285--Childid
454286--Childid
454287--Childid
Please provide solution for this.Thanks.
March 5, 2009 at 5:06 am
Thanks a lot this is working fine. Feeling great to use the this portal for queries.:)
Viewing 7 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply