2011/5/13 Fabiano Fernandes <cont...@fabianofernandes.adm.br> > Preciso unir em uma query 2 resultados ... > > Os selects separadamente funcionam perfeitamente (ambas com a mesma > estrutura de dados). Mas se eu coloco UNION entre esses 2 SELECT ele dá erro > ... > > <corte> > > Vc poderia demonstrar COMO fez o seu UNION e QUAL erro apareceu...
Mas adiantando, abaixo um exemplo baseado nos seus SELECTs que irá funcionar: (SELECT DISTINCT ON (avaliacao) e."name" AS aluno, "a".description AS avaliacao, b.note AS nota FROM acddegree AS "a" INNER JOIN acddegreeenroll AS b ON "a".degreeid = b.degreeid INNER JOIN acdenroll AS "c" ON b.enrollid = "c".enrollid INNER JOIN acdcontract AS d ON "c".contractid = d.contractid INNER JOIN basphysicalperson AS e ON d.personid = e.personid WHERE b.enrollid = 371 ORDER BY avaliacao ASC) UNION ALL *(*SELECT DISTINCT d."name" AS aluno, f.description AS avaliacao, e.note AS nota FROM acdenroll AS "a" INNER JOIN acdcontract AS b ON ("a".contractid = b.contractid) INNER JOIN acdenrollstatus AS "c" ON ("c".statusid = "a".statusid) INNER JOIN basphysicalperson AS d ON (b.personid = d.personid) INNER JOIN acdevaluationenroll AS e ON (e.enrollid = "a".enrollid) INNER JOIN acdevaluation AS f ON f.evaluationid = e.evaluationid INNER JOIN acdgroup AS "g" ON f.groupid = "g".groupid INNER JOIN acdcurriculum AS h ON "g".curriculumid = h.curriculumid INNER JOIN acdcurricularcomponent AS i ON h.curricularcomponentid = i.curricularcomponentid WHERE "a".groupid = '20' AND d."name" <> '' ORDER BY aluno ASC) ; Cordialmente, -- Fabrízio de Royes Mello >> Blog sobre TI: http://fabriziomello.blogspot.com >> Perfil Linkedin: http://br.linkedin.com/in/fabriziomello
_______________________________________________ pgbr-geral mailing list pgbr-geral@listas.postgresql.org.br https://listas.postgresql.org.br/cgi-bin/mailman/listinfo/pgbr-geral