I have a problem with retrieve column values like depending on other column
I tried to do it with outer join and nested select but I think I can’t find the solution in my head
Categories Table:
ID Name ParentID
--------------------------------
1 Software NULL
2 Domains NULL
3 Games NULL
4 Accounts NULL
5 Others NULL
6 Security Software 1
7 Operating Systems 1
8 Browsers 1
9 Developer Tools 1
10 .com Domains 2
11 .net Domains 2
12 .org Domains 2
13 Online Games 3
14 PC Games 3
15 PS Games 3
16 RapidShare Accounts 4
17 4shared Account 4
18 Web Templates 5
19 Flash Intros 5
20 Firewall 6
21 Antivirus 6
What I want do to display parent category name
instead of parentID
Like that
ID Name ParentID
--------------------------------
1 Software NULL
2 Domains NULL
3 Games NULL
4 Accounts NULL
5 Others NULL
6 Security Software Software
7 Operating Systems Software
8 Browsers Software
9 Developer Tools Software
10 .com Domains Domains
11 .net Domains Domains
12 .org Domains Domains
13 Online Games Games
14 PC Games Games
15 PS Games Games
16 RapidShare Accounts Accounts
17 4shared Account Accounts
18 Web Templates Others
19 Flash Intros Others
20 Firewall Security Software
21 Antivirus Security Software
you need to join on the table two times
the results will be:
which will give you the parentID, parentName and Name of the subcategory or child.
You can also change it to include the subcategory id, if needed.
Based on your Edit you can use the following:
which will result in: