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 > table joining two instances of the same class

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-21-10, 04:41
pagin pagin is offline
Registered User
 
Join Date: Apr 2010
Posts: 2
table joining two instances of the same class

Hi all!

I have a problem setting up a database in OpenOffice.org Base, and I suspect it is a design problem. I want to map recommendations on human rights policy that countries can give each other at the UN. To map this, I have three tables:

Issues: PK IssueNo | Issue (e.g. 'child labour', 'juvenile justice' etc.)

Countries: PK CountryNo | CountryName | Region (e.g. Africa)

Recommendations: RecommNo | CountryAffected | CountryProposing | Issue

CountryAffected and CountryProposing should both contain CountryNos from 'Countries'. So I have two relationships between two tables. In OpenOffice's relationships window, I can design such a relationship, but if I try to wrap everything into a query showing the countries' names, it doesn't know which countryname it has to display for a column, as there are two relationships...
Could anyone help me out how to fix this? I am quite new to DB design...

Thanks!
Philippe
Reply With Quote
  #2 (permalink)  
Old 04-21-10, 04:54
pootle flump pootle flump is offline
King of Understatement
 
Join Date: Feb 2004
Location: One Flump in One Place
Posts: 14,905
Can you post your SQL please?
Reply With Quote
  #3 (permalink)  
Old 04-21-10, 05:15
pagin pagin is offline
Registered User
 
Join Date: Apr 2010
Posts: 2
The SQL for the query is here:
Code:
SELECT "atmUprSessions"."SessionNo", "relRecommendations"."CountryAffected", "atmCountries"."CountryName", "relRecommendations"."Issue" FROM "relRecommendations", "atmCountries", "atmIssues", "atmUprSessions" WHERE "relRecommendations"."CountryAsking" = "atmCountries"."CountryNo" AND "relRecommendations"."Issue" = "atmIssues"."IssueNo" AND "relRecommendations"."UprSession" = "atmUprSessions"."UprNo"
Reply With Quote
  #4 (permalink)  
Old 04-21-10, 05:28
pootle flump pootle flump is offline
King of Understatement
 
Join Date: Feb 2004
Location: One Flump in One Place
Posts: 14,905
I don't know the syntax for that RDBMS but hopefully you can see what is going on:
Code:
SELECT "atmUprSessions"."SessionNo"
    , "relRecommendations"."CountryAffected"
    , "CountryProposing"."CountryName" AS "CountryProposing"
    , "CountryAsking"."CountryName" AS "CountryAsking"
    , "relRecommendations"."Issue" 
FROM     "relRecommendations", "atmCountries" AS "CountryAsking", "atmIssues", "atmUprSessions", "atmCountries" AS "CountryProposing"
WHERE     "relRecommendations"."CountryAsking" = "CountryAsking"."CountryNo" 
    AND "relRecommendations"."Issue" = "atmIssues"."IssueNo" 
    AND "relRecommendations"."UprSession" = "atmUprSessions"."UprNo"
    AND "relRecommendations"."CountryProposing" = "CountryProposing"."CountryNo"
If not, look up "aliases"
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