Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Community Forums
 Community Discussions (All other subjects)
 Two forignkeys to one primary key
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

user
Starting Member

36 Posts

Posted - 30 April 2004 :  14:15:04  Show Profile
I have three tables as model a, model_upc b, agencypower c. The structure is the following

table:Model as a
a.model_seq_num
a.boxlable_model_desc
a.partnumber
a.agencypower_id1
a.agencypower_id2

table:Model_UPC as b

Model_seq_num
UPCCode

table:Agencypower C
Agencypower_id
Agencypower_desc

Query I wrote:
select a.model_seq_number, a.boxlabel_model_desc, a.agencylabel_model_desc,a.partnumber, a.upd_by, a.upd_time, b.UPCCode,b.upd_by as requester, b.upd_time as DateIssued, c.agencypower_desc from model a, model_upc b, agencypower c where a.model_seq_number=b.model_seq_number and
a.agencypower_id1=c.agencypower_id

The query above 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!




Edited by - user on 30 April 2004 14:16:44

user
Starting Member

36 Posts

Posted - 30 April 2004 :  16:40:38  Show Profile
I found the answer.
The following query works. Posting it here if in case anyone needs it.

----------------------

select a.model_seq_number, a.boxlabel_model_desc, a.agencylabel_model_desc,a.partnumber, a.upd_by, a.upd_time, b.UPCCode,b.upd_by as requester, b.upd_time as DateIssued, c.agencypower_desc, d.agencypower_desc from model a, model_upc b, agencypower c, agencypower d where a.model_seq_number=b.model_seq_number and a.agencypower_id1=c.agencypower_id and
a.agencypower_id2 = d.agencypower_id

Edited by - user on 30 April 2004 16:41:04
Go to Top of Page

D3mon
Senior Member

United Kingdom
1685 Posts

Posted - 01 May 2004 :  07:21:44  Show Profile  Visit D3mon's Homepage
Nice work.
Couple of tips for you here to make SQL easier:

Give you Queries more structure:

SELECT
  a.model_seq_number,
  a.boxlabel_model_desc,
  a.agencylabel_model_desc,
  a.partnumber,
  a.upd_by,
  a.upd_time,
  b.UPCCode,
  b.upd_by as requester,
  b.upd_time as DateIssued,
  c.agencypower_desc,
  d.agencypower_desc  
FROM
  model a,
  model_upc b,
  agencypower c,
  agencypower d
WHERE
  a.model_seq_number = b.model_seq_number
  AND a.agencypower_id1 = c.agencypower_id
  AND a.agencypower_id2 = d.agencypower_id 

also, when using table aliases, give them useful names like,

SELECT
  mdl.model_seq_number,
  mdl.boxlabel_model_desc,
  mdl.agencylabel_model_desc,
  mdl.partnumber,
  mdl.upd_by,
  mdl.upd_time,
  mdlu.UPCCode,
  mdlu.upd_by as requester,
  mdlu.upd_time as DateIssued,
  ap.agencypower_desc,
  ap2.agencypower_desc
FROM
  model mdl,
  model_upc mdlu,
  agencypower ap,
  agencypower ap2
WHERE
  mdl.model_seq_number = mdlu.model_seq_number
  AND mdl.agencypower_id1 = ap.agencypower_id
  AND mdl.agencypower_id2 = ap2.agencypower_id 


Snitz 'Speedball' : Site Integration Mod : Friendly Registration Mod
"In war, the victorious strategist only seeks battle after the victory has been won"

Edited by - D3mon on 01 May 2004 07:28:35
Go to Top of Page

user
Starting Member

36 Posts

Posted - 04 May 2004 :  15:08:51  Show Profile
Thank You!
Go to Top of Page

user
Starting Member

36 Posts

Posted - 04 May 2004 :  15:10:01  Show Profile
Hi D3Mon,

Thank You for your suggestions.

Edited by - user on 04 May 2004 15:10:39
Go to Top of Page

D3mon
Senior Member

United Kingdom
1685 Posts

Posted - 04 May 2004 :  15:56:07  Show Profile  Visit D3mon's Homepage
No problem


Snitz 'Speedball' : Site Integration Mod : Friendly Registration Mod
"In war, the victorious strategist only seeks battle after the victory has been won"
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.27 seconds. Powered By: Snitz Forums 2000 Version 3.4.07