Jump to content

SORT using the field in another table?


Recommended Posts

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 :D

Link to comment
https://forums.phpfreaks.com/topic/1226-sort-using-the-field-in-another-table/
Share on other sites

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

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 :D

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.