Jump to content

Recommended Posts

i am trying to do a full join for 3 tables

i know how to make full join for 2 tables using left,right joins and union all but when i tried to join the third table i got some errors

 

i tried this one:

SELECT gcap,tcap FROM
(SELECT type.caption as tcap,genre.caption as gcap
FROM   type 
       LEFT JOIN genre 
          ON type.id = genre.id
UNION
SELECT type.caption as tcap,genre.caption as gcap
FROM   type
       RIGHT JOIN genre
          ON type.id = genre.id 
WHERE  type.id IS NULL 
)a
LEFT JOIN category ON category.id = type.id

 

Any help is welcome

Thanks in advance

Vintox

Link to comment
https://forums.phpfreaks.com/topic/174710-need-help-with-full-join-3-tables/
Share on other sites

SELECT gcap, tcap 
FROM (...) a LEFT JOIN category ON category.id = type.id

You are referring to type.id when there is no table "type" in the query, so no "id" field to check.  I'm guessing you want to return the "id" column in the psuedo table

(SELECT type.id, type.caption as tcap,genre.caption as gcap
FROM   type
       LEFT JOIN genre
          ON type.id = genre.id
UNION
SELECT type.id, type.caption as tcap,genre.caption as gcap
FROM   type
       RIGHT JOIN genre
          ON type.id = genre.id
WHERE  type.id IS NULL )

( or maybe that second type.id should be genre.id? )

 

and then JOIN ON "a.id" in the main SELECT.

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.