Domanda

I have 2 tables :

albums (idalbum, idauthor, idcompositor, idfeat)
people (id, firstname, last name)

My current Query :

SELECT * FROM albums where idalbum=:id
INNER JOIN people ON albums.idauthor = people.id
INNER JOIN people ON albums.idcompositor = people.id
INNER JOIN people ON albums.idfeat = people.id

What I want to do with my query :

[Album], [Author[First Name, Last Name]], [Compositor[First Name, Last Name]], [Feat[First Name, Last Name]]

My problem:
I have an error : SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax;

È stato utile?

Soluzione

You need to correct your query where clause should be used after your join statements and also you are not using proper table names, according to structure shown in question you can write your query as

SELECT * FROM albums  a
INNER JOIN people p ON a.idauthor = p.id
INNER JOIN people p1 ON a.idcompositor = p1.id
INNER JOIN people p2 ON a.idfeat = p2.id
where a.idalbum=:id
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top