How can linking three table in just one Query?

Hello

I have three MySQL table:Users

  • Users
  • Main Invoices
  • ٍSecond Invoices

How can i execute a query to “JOIN” in three table by OUTER JOIN?
This query won’t working:

SELECT
    users.user_id AS u_id,
    users.full_name AS u_name,
    users.gender AS u_gen,
    minvoices.invoice AS mInvoice,
    sinvoices.invoice AS nInvoice
FROM
    site_users AS users OUTER JOIN site_main_invoices AS minvoices USING(user_id) 
    OUTER JOIN site_sec_invoiceso AS sinvoices

How are the three tables connected (join fields)?
And what does ‘not working’ mean?

How are the three tables connected (join fields)?
And what does ‘not working’ mean?

Tables:

  • Users
  • Main Invoices
  • Second Invoices

easily:
How can “Outer Join” them?

You didn’t answer any of the two questions…

You didn’t answer any of the two questions…

  • All three tables connected with “user_id” field.
  • I want to get the result from them (three table) By “user_id” field.
  • I want to use “OUTER JOIN” for “Main Invoices” and “Second Invoices” table because maybe no records in one of these tables.

Any other question?


SELECT
    users.user_id AS u_id
  , users.full_name AS u_name
  , users.gender AS u_gen
  , minvoices.invoice AS mInvoice
  , sinvoices.invoice AS nInvoice
FROM site_users AS users 
OUTER JOIN site_main_invoices AS minvoices 
ON users.user_id = minvoices.user_id
OUTER JOIN site_sec_invoiceso AS sinvoices
ON users.user_id = sinvoices.user_id

Any other question?

Well, you never answered the second question. But I think the query above should do the trick. Probably the problem was you didn’t specify the second join’s ON clause :slight_smile:

does not work:

#1064 - You have an error in your SQL syntax; check  the manual that corresponds to your MySQL server version for the right  syntax to use near 'OUTER JOIN `site_main_invoices` AS main_inv 									ON users.user_id = site_main_inf' at line 15

O yeah, it’s LEFT OUTER JOIN

So I guess that’s what ‘not working’ meant :smiley:

guido, i thought you were an sql machine

it is nice to see you are human

:award:

:lol:
I don’t always check everything. There has to remain some learning experience :wink:

I can’t understand anyone here.
I need a solution for this issue. Anyone can help please?

Oh yeah
It’s LEFT OUTER JOIN
Thanks