Jump to content

Archived

This topic is now archived and is closed to further replies.

matd

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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

×

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.