matd Posted October 27, 2003 Share Posted October 27, 2003 Hi, I have one table called \'items\'. Now i\'m storing a category code for all the different items called \'cat_code\'. I have another table called \'categories\'. one of the fields in this table is \'cat_code\' and the other is \'cat_desc\'. cat_desc is obviously the description which relates to the cat_code :wink: What i\'d like to do is SORT items by cat_desc So somehow how i need to lookup \'cat_desc\' using the \'cat_code\' in the items table and then sort by \'cat_desc\'. Anybody know how to do this? Any help, as always, greatly appreciated Quote Link to comment https://forums.phpfreaks.com/topic/1226-sort-using-the-field-in-another-table/ Share on other sites More sharing options...
cougarhockey Posted October 28, 2003 Share Posted October 28, 2003 i\'m in an ORACLE class now....i\'m not sure if this is oracle proprietary or if it\'s SQL but what you do is when you say SELECT blah blah blah FROM items, categories you want to give them an abreviation like FROM items i, categories c so you then use the abreviation and a period in front of which column you want from which table...example SELECT i.item_name, c.cat_desc FROM items i, categories c WHERE i.cat_code=c.cat_code hope this works, it does when dealing with oracle Quote Link to comment https://forums.phpfreaks.com/topic/1226-sort-using-the-field-in-another-table/#findComment-4123 Share on other sites More sharing options...
matd Posted October 28, 2003 Author Share Posted October 28, 2003 Hi cougarhockey, Thanks for the reply. Can you give me an example of how you\'d implement this, but sorting using the cat_code from items and using it to sort by cat_desc in categories. cat_code being the relative field in both items and categories. Heres the structure of the 2 tables :- categories table : cat_code cat_desc autog Autographs co Covers ab Albums test Test Description items table : ID cat_code caption price 13 autog A Smith 4.00 14 autog B Jones 2.00 15 co J Smith 1.00 16 ab Test Album 4.00 I\'d like to sort items by using the cat_code value and using it to sort by the cat_desc field in categories. If you could give me an example that\'d be great Quote Link to comment https://forums.phpfreaks.com/topic/1226-sort-using-the-field-in-another-table/#findComment-4124 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.