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 > Data Access, Manipulation & Batch Languages > ANSI SQL > ANSI syntax for joining 4 tables-am I correct?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-17-09, 17:41
andierosebud andierosebud is offline
Registered User
 
Join Date: Oct 2009
Posts: 1
Question ANSI syntax for joining 4 tables-am I correct?

Hi, I'm new to these forums and I've searched everywhere and can only find syntax and examples on how to join 2 and 3 tables using ANSI, but I need to join 4. For a traditional join it would be:

SELECT a.one, a.two, b.one, b.three, b.four, d.seven
FROM tablea a, tableb b, tablec c, tabled d
WHERE a.one = b.one
AND a.two = c.two
AND c.six = d.six;

Here are the tables:

_tableb_
one
three
four

_tablea_
one
two

_tablec_
two
six

_tabled_
six
seven
eight

Does anyone know how to do this using an ANSI join or have any resources that can point me in the right direction. I know if I wanted to join three tables it would be:

SELECT a.one, a.two, b.one, b.three, b.four, c.six
FROM tableb b JOIN tablea a ON b.one = a.one JOIN tablec c ON a.two = c.two;

so would joining a fourth be:

SELECT a.one, a.two, b.one, b.three, b.four, d.seven
FROM tableb b JOIN tablea a ON b.one = a.one JOIN tablec c ON a.two = c.two JOIN tabled d ON c.six = d.six; ???

Is the above correct or is there another way to do this using an ANSI Join?
Reply With Quote
  #2 (permalink)  
Old 10-17-09, 18:28
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,511
Quote:
Originally Posted by andierosebud
Is the above correct ...
what happpened when you tested it?

Quote:
Originally Posted by andierosebud
... or is there another way to do this using an ANSI Join?
actually, the old style of joins is also compatible with ANSI SQL --

SELECT a.one, a.two, b.one, b.three, b.four, d.seven
FROM tablea a, tableb b, tablec c, tabled d
WHERE a.one = b.one
AND a.two = c.two
AND c.six = d.six;

however, most people agree that using JOIN syntax is better
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
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