0

If I was to have a SQL query as such:

SELECT * FROM tableA a
INNER JOIN TABLEB b on a.item = b.item
INNER JOIN TABLEC c on a.item = c.item
LEFT JOIN TABLED d on d.item = c.item

Am I right in assuming the following:

  1. Firstly, Table A is joined with Table B
  2. Table C is joined with Table A independently of statement 1
  3. Table D is left joined with table C indepdendently of Statement 1 and 2
  4. The results of statement 1,2 and 3 and listed all together from the select
Aiden
  • 179
  • 2
  • 13

1 Answers1

0

No, you are not correct. SQL is a descriptive language, not a procedural language. A SQL query describes the result set but does not specify how the query is actually executed.

In fact, almost all databases execute queries using directed acyclic graphs (DAGs). The operators in the graphs have names, but they do not correspond to the clauses in SQL.

In other words, the query is compiled to a language that you would not recognize. Along the way, it is optimized. A key part of the optimization is determining the order of the join operations.

In terms of interpreting what the query means, the joins are grouped from left to right (in the absence of parentheses):

SELECT *
FROM ((tableA a INNER JOIN
       TABLEB b
       on a.item = b.item
      ) INNER JOIN
      TABLEC c
      on a.item = c.item
     ) LEFT JOIN
     TABLED d
     on d.item = c.item

I believe this is basically what you have described.

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786