Hi, I have a query which works fine.
SELECT PAPA.idPAPA AS PAPA, HIJO.idHIJO AS HIJO, NIETO.idNIETO AS NIETO,
BISNIETO.idBISNIETO AS BISNIETO
FROM PAPA
LEFT JOIN HIJO ON HIJO.PreH=PAPA.idPAPA
LEFT JOIN NIETO ON NIETO.PreN=HIJO.idHIJO
LEFT JOIN BISNIETO ON BISNIETO.PreB=NIETO.idNIETO
ORDER BY idPAPA,idHIJO,idNIETO,idBISNIETO ASC;
The following table returns me, when I already enter 2 different PARENTS:
Which is correct, however, I want to add a WHERE idPAPA="A", so that it only gives me the query for PAPA "A".
I have this query but it doesn't run.
SELECT idPAPA, idHIJO, idNIETO, idBISNIETO
FROM
(SELECT PAPA.idPAPA AS PAPA, HIJO.idHIJO AS HIJO,NIETO.idNIETO AS
NIETO,BISNIETO.idBISNIETO AS BISNIETO
FROM PAPA
LEFT JOIN HIJO ON HIJO.PreH=PAPA.idPAPA
LEFT JOIN NIETO ON NIETO.PreN=HIJO.idHIJO
LEFT JOIN BISNIETO ON BISNIETO.PreB=NIETO.idNIETO
WHERE idPAPA="A"
) ORDER BY idPAPA,idHIJO,idNIETO,idBISNIETO ASC
;
Thanks.
The tables inside the query must have a name, try this: