I can not nest joins with SQL statements in Access 2013

0

I test this in Access 2013 and says there is an error, but it does not specify which one.

SELECT DISTINCT factura.n_factura, factura.data, factura.import, factura.concepte, departament.nom, programa.nom, despesa.nom, emisor.nom, destinatari.nom
FROM factura
INNER JOIN departament  ON factura.departament = departament.codi
INNER JOIN programa ON factura.programa = programa.codi
INNER JOIN despesa ON factura.despesa = despesa.codi
INNER JOIN emisor ON factura.emisor = emisor.codi
INNER JOIN destinatari ON factura.destinatari = destinatari.codi;

I have tried the examples of MSDN and it is very annoying to see how bad the official documentation of Microsoft is.

How can I nest the JOIN without errors?

    
asked by JoelBonetR 02.12.2016 в 19:52
source

3 answers

1

In the end I solved it by generating the query from the access itself and modifying it, and it remained as post a priori (also generated by access and modified by me), but this time working.

Quite funny the fact of seeing a Microsoft software giving different responses to the same stimulus, huh? (wink-wink, genius meme with "maicroso" logo on the cap) Anyway, thanks for the answers anyway and if someone has the same problem, delete and rebuild query!

Greetings

    
answered by 03.03.2017 / 17:29
source
1

Considering the response of my good friend @sstan and the answer seen in SOen You must have the following:

SELECT DISTINCT factura.n_factura, factura.data, factura.import, factura.concepte, departament.nom, programa.nom, despesa.nom, emisor.nom, destinatari.nom
FROM (((((factura
INNER JOIN departament  ON factura.departament = departament.codi)
INNER JOIN programa ON factura.programa = programa.codi)
INNER JOIN despesa ON factura.despesa = despesa.codi)
INNER JOIN emisor ON factura.emisor = emisor.codi)
INNER JOIN destinatari ON factura.destinatari = destinatari.codi)
    
answered by 02.03.2017 в 18:51
0

I do not have Access on my computer to test it. But if I remember correctly, with Access, if you make more than one join, you have to group them using parentheses.

Something like:

SELECT DISTINCT factura.n_factura, factura.data, factura.import, factura.concepte, departament.nom, programa.nom, despesa.nom, emisor.nom, destinatari.nom
FROM ((((factura
INNER JOIN departament  ON factura.departament = departament.codi)
INNER JOIN programa ON factura.programa = programa.codi)
INNER JOIN despesa ON factura.despesa = despesa.codi)
INNER JOIN emisor ON factura.emisor = emisor.codi)
INNER JOIN destinatari ON factura.destinatari = destinatari.codi;

Also, if I remember correctly, although Access accepts the parentheses and executes the query correctly, the next time you try to edit the query, Access may break the parentheses. At least, I think that was my experience, but I do not remember well. I mention it to be careful. My experience with Access has always been somewhat frustrating.

    
answered by 04.12.2016 в 03:18