To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here

HOME News MS SQL Oracle DB2 Access MySQL PHP Scripts Books Links DBA Talk


Go Back   Database Journal Forums > Related Sites > SQL Course

SQL Course SQL Course > Ask questions about the lessons on SQL Course 1 and 2. If you have problems > with the interface, please post in the Feedback forum

Reply Post New Thread
 
Thread Tools Search this Thread Rate Thread Display Modes
  #1  
Old 02-26-2003, 04:53 AM
schockp schockp is offline
Junior Member
 
Join Date: Feb 2003
Posts: 1
Question Join of 4 tables

Hi,

After a few years of not using SQL, I have some problems to find the right query. There are 4 tables:
Substance: ID, Name
SubstanceProperty: ID, SubstanceID, Value, PropertyPropertyGroupID
PropertyPropertyGroup: ID, PropertyID
Property: ID, Code

In each table 'ID' is the primary key. SubstanceID links to Substance.ID, PropertyPropertyGroupID to PropertyPropertyGroup.ID and PropertyPropertyGroupID.PropertyID to Property.ID. Now I want to select the Code of the Property, the Value of the PropertyPropertyGroup and the Name of a Substance for a specific Substance.ID.

How can I handle this?

thx,
Pieter
Reply With Quote
  #2  
Old 02-26-2003, 05:50 AM
PinkPanther2003 PinkPanther2003 is offline
Senior Member
 
Join Date: Feb 2003
Posts: 102
SELECT P.Code, PPG.ID, S.Name
FROM Substance as S
INNER JOIN SubstanceProperty as SP
ON S.ID = SP.SubstanceID
INNER JOIN PropertyPropertyGroup PPG
ON PPG.ID = SP.PropertyPropertyGroupID
INNER JOIN Property P
ON P.ID = PPG.ID

Should do the trick if the RDBMS (which you didn't mention which one it was) supports joins (I would be very surprise if it didn't but some don't).

HTH,

Peter
Reply With Quote
Reply Post New Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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
Forum Jump


All times are GMT -5. The time now is 07:30 AM.


DatabaseJournal Recent Articles


 » Grouping with SQL Server 2008

 » Conducting Service Broker Conversation Usi...

 » Applying data warehousing principles to ev...

 » Oracle New Year's resolutions, part 1: Adv...

 » Hands on: Understanding SQL queries

Search Database Journal:
 





Acceptable Use Policy

JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Web Hosting | Newsletters | Tech Jobs | Shopping | E-mail Offers

Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.