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 > General > Database Concepts & Design > A table with 2 extern ID in the same row...?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-23-06, 04:40
bikelink bikelink is offline
Registered User
 
Join Date: Feb 2003
Posts: 3
A table with 2 extern ID in the same row...?

Table1 :

Code (Primary key) │ ID-Desc1 │ ID-Desc2
"aaaaa" │ 100 │ 3450
"bbbbb" │ 102 │ 3454


________________________________________________

Table2

IDDescGeneric │ DescriptionText │ IDlanguage ecc...
100 │ art1 │ 1031
102 │ art2 │ 1031
3450 │ art3 │ 1031
3454 │ art4 │ 1031


I need to obtain rows as
"aaaaa" │ art1 | art3
"bbbbb" │ art2 | art4

the structure already exists..
Do you think that's a good choice to have 2 IDs fields in the same row, in order to obtain a value from unique ID from another table ?
I'm not that's good...but i'm not very expert..

I suppose to obtain the result that I need to write a nested query... or divide the tables..

Any suggest to works better ?
Reply With Quote
  #2 (permalink)  
Old 03-23-06, 07:08
andrewst andrewst is offline
Moderator.
 
Join Date: Sep 2002
Location: UK
Posts: 5,171
You can query it easily enough just by joining to the lookup table twice:

select ...
from table1
join table2 t2a on t2a.IDDescGeneric = table1.IDdesc1
join table2 t2b on t2b.IDDescGeneric = table1.IDdesc2;

There is nothing wrong in principle in having two foreign keys from one table referening the same parent table - e.g. a bank transfer table might have a from_account_id and a to_account_id. However what you have here looks to me suspiciously like a One True Lookup Table which as you can see from that link, I don't like.
__________________
Tony Andrews
http://tinyurl.com/tonyandrews
Reply With Quote
  #3 (permalink)  
Old 03-23-06, 07:13
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
Quote:
Originally Posted by bikelink
Do you think that's a good choice to have 2 IDs fields in the same row, in order to obtain a value from unique ID from another table ?
this is a very common structure

sometimes it is better to have multiple occurrences in a separate one-to-many table, but it is often also okay to have two of them side by side the way you have it
Code:
select t1.code
     , t2one.DescriptionText as Description_one
     , t2two.DescriptionText as Description_two
  from Table1 as t1
inner
  join Table2 as t2one
    on t2one.IDDescGeneric = t1.IDDesc1
inner
  join Table2 as t2two
    on t2two.IDDescGeneric = t1.IDDesc2
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #4 (permalink)  
Old 03-23-06, 07:14
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
rats, tony beat me again
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 03-24-06, 05:40
bikelink bikelink is offline
Registered User
 
Join Date: Feb 2003
Posts: 3
Quote:
Originally Posted by r937
this is a very common structure

sometimes it is better to have multiple occurrences in a separate one-to-many table, but it is often also okay to have two of them side by side the way you have it
Code:
select t1.code
     , t2one.DescriptionText as Description_one
     , t2two.DescriptionText as Description_two
  from Table1 as t1
inner
  join Table2 as t2one
    on t2one.IDDescGeneric = t1.IDDesc1
inner
  join Table2 as t2two
    on t2two.IDDescGeneric = t1.IDDesc2


ok ! Thank you. now i'm going to try it
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