Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query Help 1

Status
Not open for further replies.

overDeveloper

Programmer
Dec 11, 2006
58
US
Given the follwoing table:

id name parentid
1 aaa 0
2 bbb 0
3 ccc 0
4 ZZZ 1
5 YYY 1
6 XXX 3

How can I make a query to produce the follwoing strings:

aaa
aaa/ZZZ
aaa/YYY
bbb
ccc
ccc/XXX
 
Try this...

Code:
Select A.Name + '/' + B.Name As OutputColumn
From   [!]TableName[/!] A
       Inner Join [!]TableName[/!] B
         On A.Id = B.ParentId
Union All

Select Name
From   [!]TableName[/!] 
Where  ParentId = 0

Order By OutputColumn

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top