If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Data retrieval question

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-31-03, 17:11
macjoubert macjoubert is offline
Registered User
 
Join Date: Oct 2003
Location: Rhodesia
Posts: 28
Data retrieval question

Hi I had a question 2 parts I got the first part.

I have the following tables(just the keys for used for joining are mentioned)

Sub Category SC_ID (PK)
Class C_ID(PK), SC_ID (FK)
Product P_ID(PK), C_ID (FK)
UPC UPC_ID ,P_ID(FK)
A product may have more than 1 UPC


input value =UPC_id

I have obtained SC_ID going upward
(Now I know what sub cat, class and product the input UPC belongs to)

Now I need to retrieve all UPCs under that Sub Category how do I do this
thanks
prester
Reply With Quote
  #2 (permalink)  
Old 10-31-03, 18:44
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
given an input value for a UPC, you can actually get all the other UPCs in the same SubCategory in one query like this --
Code:
select SC.SC_ID     as subcategory
     , Cdown.C_ID   as classdown
     , Pdown.P_ID   as productdown
     , Udown.UPC_ID as UPCdown
  from UPC UPCup
inner
  join Product Pup
    on UPCup.P_ID = Pup.P_ID
inner
  join Class Cup
    on Pup.C_ID = Cup.C_ID
inner      
  join SubCategory
    on Cup.SC_ID = SubcCategory.SC_ID
inner
  join Class Cdown
    on SubcCategory.SC_ID = Cdown.SC_ID
inner
  join Product Pup
    on Cdown.C_ID = Pdown.C_ID    
inner
  join UPC UPCdown
    on Pdown.P_ID = UPCdown.P_ID
 where UPCup = 'inputvalue'
rudy
http://r937.com/
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On