Problem with multiple INNER JOIN

J

JLuis Estrada

I got a problem with the next query:

SELECT Pacientes.Clv_Pac, Pacientes.Nom, Pacientes.A_Pat,
Pacientes.A_Mat,Pacientes.Ema, Pacientes.Refe, Pacientes.FecNac,
Pacientes.Civ, Pacientes.Sex, Pacientes.Pes,Pacientes.San, Pacientes.Eda,
Pacientes.Esta, Pacientes_Cat.Clave, Pacientes_Ocu.Des_Ocu,Pacientes_Tel.Num
FROM Pacientes INNER JOIN Pacientes_Ocu ON Pacientes.Clv_Ocu =
Pacientes_Ocu.Clv_Ocu, INNER JOIN Pacientes_Cat ON Pacientes.Clv_Pac =
Pacientes_Cat.Clv_Cat, INNER JOIN Pacientes_Tel ON Pacientes.Clv_Pac =
Pacientes_Tel.Clv_Pac WHERE Pacientes.Clv_Pac = '1' AND Pacientes_Tel.Pred =
True

can somebody tell me whats wrong with it?
 
G

Guest

The syntax is:

SELECT Pacientes.Clv_Pac, Pacientes.Nom, Pacientes.A_Pat,
Pacientes.A_Mat,Pacientes.Ema, Pacientes.Refe, Pacientes.FecNac,
Pacientes.Civ, Pacientes.Sex, Pacientes.Pes,Pacientes.San, Pacientes.Eda,
Pacientes.Esta, Pacientes_Cat.Clave, Pacientes_Ocu.Des_Ocu,Pacientes_Tel.Num
FROM Pacientes INNER JOIN Pacientes_Ocu
ON Pacientes.Clv_Ocu = Pacientes_Ocu.Clv_Ocu
INNER JOIN Pacientes_Cat
ON Pacientes.Clv_Pac = Pacientes_Cat.Clv_Cat
INNER JOIN Pacientes_Tel
ON Pacientes.Clv_Pac = Pacientes_Tel.Clv_Pac
WHERE Pacientes.Clv_Pac = '1' AND Pacientes_Tel.Pred = True

There should not be commas separating the join condition from the INNER JOIN
keywords.
 
R

Rick Brandt

JLuis said:
I got a problem with the next query:

SELECT Pacientes.Clv_Pac, Pacientes.Nom, Pacientes.A_Pat,
Pacientes.A_Mat,Pacientes.Ema, Pacientes.Refe, Pacientes.FecNac,
Pacientes.Civ, Pacientes.Sex, Pacientes.Pes,Pacientes.San,
Pacientes.Eda, Pacientes.Esta, Pacientes_Cat.Clave,
Pacientes_Ocu.Des_Ocu,Pacientes_Tel.Num FROM Pacientes INNER JOIN
Pacientes_Ocu ON Pacientes.Clv_Ocu = Pacientes_Ocu.Clv_Ocu, INNER
JOIN Pacientes_Cat ON Pacientes.Clv_Pac = Pacientes_Cat.Clv_Cat,
INNER JOIN Pacientes_Tel ON Pacientes.Clv_Pac =
Pacientes_Tel.Clv_Pac WHERE Pacientes.Clv_Pac = '1' AND
Pacientes_Tel.Pred = True

can somebody tell me whats wrong with it?

How about telling us what the problem is?

What do expect it to do and what does it actually do?
 
J

JLuis Estrada

Tnx for ur fast answering

but when I tried to rund this query on Access, the next error appears:

Syntax Error (operator missing) in the query string 'Pacientes.Clv_Ocu =
Pacientes_Ocu.Clv_Ocu INNER JOIN Pacientes_Cat ON Pacientes.Clv_Pac =
Pacientes_Cat.Clv_Cat INNER JOIN Pacientes_Tel ON Pacientes.Clv_Pac =
Pacientes_Tel.Clv_Pac'

do you why this happened
jluis
 
J

JLuis Estrada

Well, I got 4 tables. 1 main (Pacientes) and 3 secondary (Pacientes_Tel,
Pacietnes_Cat, Pacientes_Ocu)

What I need is all the data froma Pacient in particular (Clv_Pac = '1').

In my 1st table I got all the main data (address, name, age, sex, weitgh,
etc) and in the other tables I got the phone numbes (Pacientes_Tel),
Category ID (Pacientes_Cat.Clave) and Job Name (Pacientes_Ocu.Des_Ocu)

And I need all those field in only one query to the BD.

What I saw in other examples is that i gotta use LEFT JOIN instead INNER
JOIN because in some cases there will be no fields with my user in the
secondary tables.

One more thing. in the WHERE part, theres a mistake of mine because in there
im forcing to the table Pacientes_Tel to have that value, and thats not
true, if aint got phone numers in the table for that pacient, I will get no
data even if I got values in all the other 3 tables.
 
V

Van T. Dinh

Are you talking about JET SQL?

In JET SQL, you need parentheses for all the joins, not comma except the
outer most join like:

SELECT Pacientes.Clv_Pac, Pacientes.Nom, Pacientes.A_Pat,
Pacientes.A_Mat,Pacientes.Ema, Pacientes.Refe, Pacientes.FecNac,
Pacientes.Civ, Pacientes.Sex, Pacientes.Pes,Pacientes.San, Pacientes.Eda,
Pacientes.Esta, Pacientes_Cat.Clave, Pacientes_Ocu.Des_Ocu,Pacientes_Tel.Num
FROM ((Pacientes INNER JOIN
Pacientes_Ocu ON Pacientes.Clv_Ocu = Pacientes_Ocu.Clv_Ocu) INNER JOIN
Pacientes_Cat ON Pacientes.Clv_Pac = Pacientes_Cat.Clv_Cat) INNER JOIN
Pacientes_Tel ON Pacientes.Clv_Pac = Pacientes_Tel.Clv_Pac
WHERE (Pacientes.Clv_Pac = '1') AND
(Pacientes_Tel.Pred = True)

HTH
Van T. Dinh
MVP (Access)
 
Top