0

Hello i'm trying to join 3 tables , in T1 i have id for T2 and T3. But i always get this error:

Syntax error (missing operator) in query expression '(T2.id_apartmana = T1.id_apartmana) INNER JOIN tblPacijenti T3 ON (T3.id_pacijenta = T1.id_pacijenta)'.

This is my sql code:

SELECT *
FROM   tblapartmanirezervacije AS T1
       INNER JOIN tblapartmani AS T2
               ON ( T2.id_apartmana = T1.id_apartmana )
       INNER JOIN tblpacijenti T3
               ON ( T3.id_pacijenta = T1.id_pacijenta )
WHERE  T1.status = 'true'

I use access database.

Warix3
  • 99
  • 1
  • 11
  • 1
    https://stackoverflow.com/questions/7854969/sql-multiple-join-statement – PhillipD Sep 24 '17 at 20:34
  • 1
    Thank you, adding the parenthesis solved the problem. I was actually searching for this before posting the question but i didn't find that answer. – Warix3 Sep 24 '17 at 20:39

2 Answers2

0

Try this :

SELECT * FROM tblapartmanirezervacije AS T1 INNER JOIN tblapartmani AS T2 ON T1.id_apartmana = T2.id_apartmana INNER JOIN tblpacijenti T3 ON T1.id_pacijenta = T3.id_pacijenta AND T1.status = 'true'

0

MS Access requires extra parentheses when joining multiple tables:

SELECT *
FROM (tblapartmanirezervacije AS T1 INNER JOIN
      tblapartmani AS T2
      ON T2.id_apartmana = T1.id_apartmana
     ) INNER JOIN
     tblpacijenti T3
     ON T3.id_pacijenta = T1.id_pacijenta
WHERE T1.status = 'true'

A couple of suggestions:

  • Use table aliases that mean something. ar for tblapartmanirezervacije, a for tblapartmani, and so on. These are much easier to follow than arbitrary aliases.
  • List the columns that you want, instead of select *, especially when the same column appears in multiple tables.
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
  • Thank you, i already list the columns in the code, but I've just put a star there so it would be more readable, because columns are irrelevant for this issue. – Warix3 Sep 24 '17 at 21:38