I try to do INNER JOIN in SQL with 4 tables, but it doesn't work.
I use this SQL Query (this one works):
SELECT PELICULAS.*, companias.nombre AS nombreCompania
FROM companias INNER JOIN peliculas ON companias.id_compania = peliculas.id_compania
But, when I add another INNER JOIN to enter the table PELICULAS_DIRECTORES
, it doesn't work:
SELECT PELICULAS.*, companias.nombre AS nombreCompania,
DIRECTORES.nombre AS nombreDirector
FROM companias INNER JOIN peliculas ON companias.id_compania = peliculas.id_compania
FROM DIRECTORES INNER JOIN PELICULAS_DIRECTORES ON DIRECTORES.id_director = PELICULAS_DIRECTORES.id_director
Diagram:
The first Query works and shows me all the PELICULAS
and exchanges the id_compania
for the one nombre
in the table COMPANIAS
.
I want to do the same thing and get the same thing, but now, swapping the id_director
from table PELICULAS_DIRECTORES
for the nombre
from table DIRECTORES
. I mean, I want to show at the end the"id", "titulo", "anoLanzamiento", "longitudMinutos", "sinopsis", "nombreCompania", "nombreDirector"
I have tried many combinations and it does not work, what is wrong with my second Query?
In a query
SELECT
, a unique is addedFROM
and then the idsINNER JOIN
with their respectiveON
ones, joining the ids of the relational tables. Putting the tables together would look like this: