HiveBrain v1.2.0
Get Started
← Back to all entries
patternMinor

Joining 3 tables using SQL Query?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
tablessqlqueryusingjoining

Problem

I'm having problems joining three tables. It works well when I use the same query for joining two tables (after removing LEFT OUTER JOIN C ON B.No = C.No). However, it doesn't work when I use three tables.

This is my query

SELECT A.Name, B.Quantity, C.Quantity 
FROM A 
LEFT OUTER JOIN B 
    ON A.ID = B.ID 
LEFT OUTER JOIN C 
    ON B.No = C.No;

Solution

MS-Access is rather picky at how it wants the joins to be formed. Add parentheses:

SELECT A.Name, B.Quantity, C.Quantity 
FROM 
  ( A LEFT OUTER JOIN B ON A.ID = B.ID )
  LEFT OUTER JOIN C ON B.No = C.No ;


Standard SQL syntax - and most other DBMS - do not need require parentheses in the FROM clause, although you are allowed to use them for clarity.

Code Snippets

SELECT A.Name, B.Quantity, C.Quantity 
FROM 
  ( A LEFT OUTER JOIN B ON A.ID = B.ID )
  LEFT OUTER JOIN C ON B.No = C.No ;

Context

StackExchange Database Administrators Q#28095, answer score: 7

Revisions (0)

No revisions yet.