[ACCEPTED]-SQL Error: table specified more than once-postgresql

Accepted answer
Score: 13

You have joined to it twice. If you need 3 to do this, specify an alias for one of 2 your joins,

e.g.

LEFT JOIN fat_unidades AS f1 ON f1.cod_unidade ...

The duplicate join is marked 1 below

**LEFT JOIN fat_unidades** ON ( fat_unidades.cod_unidade = amb_recepcao.cod_und_atend )   
LEFT JOIN entidades atend ON ( atend.cod_entidade = fat_unidades.cod_entidade ) 
LEFT JOIN fat_atividades ON ( fat_atividades.cod_atividade = amb_recepcao.cod_atividade ) 
LEFT JOIN entidades uni_pacie ON ( uni_pacie.cod_entidade = fat_unidades.cod_entidade ) 
LEFT JOIN pacientes ON ( pacientes.cod_paciente = amb_recepcao.cod_paciente ) 
**LEFT JOIN fat_unidades** ON ( fat_unidades.cod_unidade = amb_recepcao.cod_undpaciente ) 
LEFT JOIN pessoas pacie ON ( pessoas.cod_pessoa = pacientes.cod_pessoa )
LEFT JOIN pessoas ON ( pessoas.cod_pessoa = amb_recepcao.cod_pessoa ) 
LEFT JOIN amb_sintomas ON ( amb_sintomas.cod_sintoma = amb_recepcao.cod_sintoma ) 
LEFT JOIN profissionais ON ( profissionais.cod_profissional = amb_recepcao.cod_profissional ) 
LEFT JOIN pessoas profissional ON ( pessoas.cod_pessoa = profissionais.cod_pessoa )
Score: 3

Just as the error states, you have the same 8 table fat_unidades listed twice among the source tables. The 7 database engine can't tell which table you 6 are referring to when you mention fat_unidades in data 5 expressions because both references have 4 the same name. You have to use a table alias 3 with a different name on at least one references 2 to fat_unidades so that each reference to that table 1 has a different name.

Score: 1

Use different table alias name

0

More Related questions