hi,
Check this query :
Select q.CategoryID,q.SubCategoryID,q.Category_Name
FROM
(
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