Jump to content


Photo

SORT using the field in another table?


  • Please log in to reply
2 replies to this topic

#1 matd

matd
  • Members
  • PipPip
  • Member
  • 12 posts
  • LocationUK

Posted 27 October 2003 - 01:01 AM

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

#2 cougarhockey

cougarhockey
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 28 October 2003 - 02:11 AM

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

#3 matd

matd
  • Members
  • PipPip
  • Member
  • 12 posts
  • LocationUK

Posted 28 October 2003 - 09:09 AM

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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users