36pixels Posted July 1, 2012 Share Posted July 1, 2012 (edited) HiI have a typical problem where I want to sort a table on a field which is in another table but the foreign key is different.What I mean is this-I have a table called 'staff ' with 2 fields -1)"id"(primary key) and 2)"staff_cat" as the 2nd field.Now I have another table called "stf_cat" where it has 3 fields -1)id(Primary key) ie it is auto-incremented and hence it is acting as a serial number.2)sid(short for Serial ID which represents the 'id' field of the 'staff' table.Basically this is kind of a foreign key as I mentioned above .ie. 'id' of staff table=='sid' of stf_cat table)3)The last field of this table is named "sub_cat"(short for sub category). Basically staff_cat field has values like "Teacher","Staffs","Game Teacher" etc etc like this on..And sub_cat field has values like Arts,Science,Commerce etc etc for the staff_cat "Teacher",similarly sub_cat field has values like Hockey,Cricket,BasketBall,Tennis etc etc for the staff_cat "Game Teacher",similarly for staff there is Grade 1,Grade2 "sub_cat" under the staff_cat -"staff".Now my problem is I am to display a table on the browser with the fields "sid","staff_cat","sub_cat" but it should be sorted either in ascending/desc order by staff_cat names.I have tried a lot of ways but i cannot manage to get the sub_cat names in the table.How to do that?Any help would be greatly appreciated. Edited July 24, 2012 by 36pixels Link to comment Share on other sites More sharing options...
birbal Posted July 2, 2012 Share Posted July 2, 2012 (edited) what have you tried? you can join the tables and then point to that particular field to get ordered. Edited July 2, 2012 by birbal Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now