Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Sorting based on foreign key feilds

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2006-12-01 : 08:38:06
shibu writes "I have a table 'manage_user_types' and its primary key is 'Category_ID'. There is another field 'Category_Parent_ID' which refers the 'Category_ID' in the same table. And one more field is 'Category_Name' which is related to 'Category_ID'. ie.when displaying the table in front end, 'Category_Name' is displayed under 'Category_Parent_ID'. I want to sort the table with 'Category_Name' when clicking the 'Category_Parent_ID' to sort. What should i do?"

Sean_B
Posting Yak Master

111 Posts

Posted - 2006-12-01 : 09:09:51
Hi Shibu,

Are you looking for something like this ?

*--input data--
insert into manage_user_types
select 1,1,'First' union all
select 2,1,'Second' union all
select 3,1,'Third' union all
select 4,2,'Fourth'
----
--query
---
select
Category_ID,
Category_Parent_ID,
Category_Name
from manage_user_types man
where man.Category_Parent_ID = 1
order by man.Category_Name asc

--which gives the results

Category_ID Category_Parent_ID Category_Name
1 1 First
2 1 Second
3 1 Third

?

Sean
Go to Top of Page
   

- Advertisement -