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 > Database Server Software > MySQL > Join on 3 tables

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-10-09, 09:46
thierrydollar thierrydollar is offline
Registered User
 
Join Date: Oct 2009
Posts: 2
Join on 3 tables

I would like to make a LEFT JOIN between table t1 and
the result of a JOIN between t2 and t3.

mathematically, I would write
t1 LEFT JOIN ( t2 JOIN t3)

In SQL, I only know how to make
t1 LEFT JOIN t2 ... LEFT JOIN t3
or
t1 LEFT JOIN t2 ... JOIN t3

But this doesn't give me the expected result.
How could I do this
t1 LEFT JOIN ( t2 JOIN t3)

Thanks for your help
Reply With Quote
  #2 (permalink)  
Old 10-10-09, 09:55
gvee gvee is offline
www.gvee.co.uk
 
Join Date: Jan 2007
Location: UK
Posts: 10,156
Code:
SELECT *
FROM   t1
 LEFT
  JOIN (
        SELECT *
        FROM   t2
         INNER
          JOIN t3
            ON t3.field2 = t2.field2
       ) As an_alias
    ON an_alias.field1 = t1.field1
__________________
George
Twitter | Blog
Reply With Quote
  #3 (permalink)  
Old 10-10-09, 10:28
thierrydollar thierrydollar is offline
Registered User
 
Join Date: Oct 2009
Posts: 2
Thanks

Thanks George. This works fine.
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