Home > Ask the Oracle Database / Applications Experts > Questions & Answers > Two "copies" of a lookup table in the same query
Ask The Oracle Expert: Questions & Answers
EMAIL THIS

Two "copies" of a lookup table in the same query

Rudy Limeback EXPERT RESPONSE FROM: Rudy Limeback

Pose a Question
Other Oracle Categories
Meet all Oracle Experts
Become an Expert for this site
>
QUESTION POSED ON: 17 May 2004

I have tables with the following structure:

Model
 model_seq_num
 boxlable_model_desc
 partnumber
 agencypower_id1
 agencypower_id2

Agencypower
 Agencypower_id
 Agencypower_desc

The query I wrote:

select m.model_seq_number,
m.boxlabel_model_desc, 
m.partnumber, 
ap.agencypower_desc 
from model m, 
agencypower ap 
where m.agencypower_id1 = 
ap.agencypower_id

This query would give me all I want, except for the agencypower_desc corresponding to agencypower_id2. How do I modify this query to get that result as well? Any help is highly appreciated.


>

You just need to have two "copies" of the lookup table in the query. Use table alias names to distinguish them, and column alias names to distinguish the columns in the result set.

select m.model_seq_number
     , m.boxlabel_model_desc
     , m.partnumber
     , ap1.agencypower_desc  as agencypower1
     , ap2.agencypower_desc  as agencypower2
  from model m
inner
  join agencypower ap1
    on m.agencypower_id1
     = ap1.agencypower_id
inner
  join agencypower ap2

    on m.agencypower_id2
     = ap2.agencypower_id

For More Information


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary



Search and Browse the Expert Answer Center
Search and browse more than 25,000 question and answer pairs from more than 250 TechTarget industry experts.
Browse our Expert Advice



Oracle White Papers: Fusion Middleware
HomeNewsTopicsTipsAsk the ExpertsMultimediaWhite PapersProductsBlogs
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 2003 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts