Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how inner join works

Status
Not open for further replies.

pcatalan

Programmer
Jan 21, 2003
5
CL
Hi, i have this big problem...im tring to use inner join with mysql, when i use 3 tables theres no problem, but if i add uno more, theres an error....¿?..

this is the call that works:
SELECT audiencia.fecha, imputado.rut
FROM (audiencia INNER JOIN audiencia_imputado ON audiencia.cod_audiencia = audiencia_imputado.cod_audiencia) INNER JOIN imputado ON audiencia_imputado.cod_imputado = imputado.cod_imputado

and this is the one not workingSELECT audiencia.fecha, imputado.rut
FROM ((audiencia INNER JOIN audiencia_imputado ON audiencia.cod_audiencia = audiencia_imputado.cod_audiencia) INNER JOIN imputado ON audiencia_imputado.cod_imputado = imputado.cod_imputado) INNER JOIN tipo_audiencia ON audiencia.cod_tipo_audiencia = tipo_audiencia.cod_tipo_audiencia;

this has one more table named 'tipo_audiencia'

I have no idea whats the problem, plz any help...and i have to add 3 more tables to the query :(
 
What error do you get?

You don't need the parenteses, so what happens fi you remove them?
 
I also tried without the parenteses..it doesnt work
 
what does "doesn't work" mean? mysql crashes? syntax error? too many records? not enough records? wrong records?

the query without the parentheses is fine --

SELECT audiencia.fecha
, imputado.rut
FROM audiencia
INNER JOIN audiencia_imputado
ON audiencia.cod_audiencia
= audiencia_imputado.cod_audiencia
INNER JOIN imputado
ON audiencia_imputado.cod_imputado
= imputado.cod_imputado
INNER JOIN tipo_audiencia
ON audiencia.cod_tipo_audiencia
= tipo_audiencia.cod_tipo_audiencia

this is valid sql-92

rudy
 
I know its a valid SQL, i get a syntax error from mysql...i execute the same in access and works perfect...
Now i tried with this, and it seems to work:

SELECT audiencia.fecha as fecha, audiencia.hora as hora, audiencia.rud as rud, funcionario.nombres as def, imputado.nombres as impn, imputado.apellido_pat as impa, tipo_audiencia.nombre as t_aud, delito.nombre as del, tribunal.nombre as tri FROM imputado, audiencia_imputado, audiencia, funcionario, tipo_audiencia, delito, tribunal WHERE imputado.cod_imputado=audiencia_imputado.cod_imputado AND audiencia_imputado.cod_audiencia=audiencia.cod_audiencia AND funcionario.cod_funcionario=audiencia.cod_defensor AND tipo_audiencia.cod_tipo_audiencia=audiencia.cod_tipo_audiencia AND delito.cod_delito=audiencia.cod_delito AND tribunal.cod_tribunal=audiencia.cod_tribunal AND audiencia.cod_defensor = 1 ORDER BY audiencia.fecha

a LOT of where conditions huh!....but it works FINALLY
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top