Click here to Skip to main content
15,037,006 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
My Table is-:
Category fields are-:
CategoryID, Category_Name, Category_Description
1 Science aaaaa
2 Language lllll

SubCategory fields are-:
SubCategoryID, CategoryID, SubCategory_Name, SubCategory_Description
1 1 Physics pppppppppp
2 1 Science ssssssssss
3 2 Hindi hhhh
4 2 English eeeeee
5 2 Maths mmmmmm

I want to result below in dropdown list-

Science(it is category_Name)
--Physics(it is subcategory_Name)
--Biology(it is subcategory_Name)
Langauge(it is category_Name)
--Hindi(it is subcategory_Name)
--English(it is subcategory_Name)
--Maths(it is subcategory_Name)
Updated 19-May-14 2:18am

1 solution


Check this query :

Select q.CategoryID,q.SubCategoryID,q.Category_Name
Select CategoryID,0 as SubCategoryID,Category_Name
from Category 
Union ALL
Select  CategoryID,SubCategoryID,SubCategory_Name as Category_Name
from SubCategory 
) q
order by q.CategoryID,q.SubCategoryID,q.Category_Name

Note i just used the select query you can apply your where conditions if needed

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900