0

I have this select clause that is working perfect:

SELECT 
    "Aspectos"."ID" AS "Aspecto Normativo ID", 
    "Aspectos"."Aspecto" AS "Aspecto Normativo",        
    "Fatores"."ID", "Fatores"."Fator" AS "Fator Normativo",
    "Diagnostico"."Vinculo_Final", 
    "Fatores_1"."ID", 
    "Fatores_1"."Fator" AS "Fator Determinativo", 
    "Aspectos_1"."ID" AS "Aspecto Determinativo ID", 
    "Aspectos_1"."Aspecto" AS "Aspecto Determinativo", 
    Count("Itens"."ID") AS "No Itens", 
    Count("Itens"."ID") AS "Pri"
FROM "Diagnostico" INNER JOIN ("Aspectos" AS "Aspectos_1" 
INNER JOIN (("Fontes" INNER JOIN "Itens" ON "Fontes"."ID" = "Itens"."Fonte") 
INNER JOIN ("Fatores" AS "Fatores_1" 
INNER JOIN ("Aspectos" 
INNER JOIN ("Vinculos" 
INNER JOIN "Fatores" 
ON "Vinculos"."Fator_Normativo" = "Fatores"."ID") 
ON ("Aspectos"."ID" = "Fatores"."Aspecto") 
AND ("Aspectos"."ID" = "Fatores"."Aspecto")) 
ON "Fatores_1"."ID" = "Vinculos"."Fator_Determinativo") 
ON "Itens"."ID" = "Vinculos"."Item") 
ON "Aspectos_1"."ID" = "Fatores_1"."Aspecto") 
ON "Diagnostico"."ID" = "Vinculos"."Diagnostico_ID"
GROUP BY "Aspectos"."ID", "Aspectos"."Aspecto", 
          "Fatores"."ID", "Fatores"."Fator", 
          "Diagnostico"."Vinculo_Final", 
          "Fatores_1"."ID", 
          "Fatores_1"."Fator", 
          "Aspectos_1"."ID", 
          "Aspectos_1"."Aspecto"
ORDER BY  "Aspectos"."ID", "Aspectos_1"."ID", 
         "Fatores"."Fator", "Fatores_1"."Fator";

But when I try to CREATE A VIEW with this same select I'm getting thuis error:

ERROR: column "ID" specified more than one time

Can anybody help me on this. Thanks

1
  • Can you show us your CREATE VIEW statement? Commented Feb 20, 2013 at 16:19

1 Answer 1

2

You have "Fatores"."ID" (line 4) and "Fatores_1"."ID" (line 6). Give them different aliases.

For such complex queries it is recommended to have only 1 (one) column in per line in the statement for better visibility. Also it is recommended to always give aliases to the columns.

Sign up to request clarification or add additional context in comments.

1 Comment

It's running perfectly! Thank you again vyegorov!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.