I have the following situation with 3 tables:
ocorrencias
: It has 6 columns: tipo_falha_1
to tipo_falha_6
. It is a 2-digit code, from 1 to 20.
tipo_falha
: Has a description of the faults. The cod
field is linked to occurrences by the tipo_falha
mentioned above. Additionally, it has the tipo_servico
column with a code that links to the service type. Example: Electrical fault ( tipo_falha
), Electrical ( tipo_servico
).
tipo_servico
: It has the description of the service whose type_fail points. The field cod is bound to the servlet_type of the type_file table.
My need would be to generate a query, with 6 columns, of the types of failure from 1 to 6, bringing results where you have given and null
where you have nothing. I tried the SQL below, but it is returning the error:
#1054 - Champ 'o.tipo_falha_1' inconnu dans on clause.
What can I be doing wrong?
SELECT tf1.NOME desc1, tf2.NOME AS desc2, tf3.NOME AS desc3, tf4.NOME AS desc4, tf5.NOME AS desc5, tf6.NOME AS desc6
FROM ocorrencias o, tipo_servico ts LEFT JOIN
tipo_falha tf1
on tf1.cod = o.tipo_falha_1 LEFT JOIN
tipo_falha tf2
on tf2.cod = o.tipo_falha_2 LEFT JOIN
tipo_falha tf3
on tf3.cod = o.tipo_falha_3 LEFT JOIN
tipo_falha tf4
on tf4.cod = o.tipo_falha_4 LEFT JOIN
tipo_falha tf5
on tf5.cod = o.tipo_falha_5 LEFT JOIN
tipo_falha tf6
on tf6.cod = o.tipo_falha_6
where
o.cod= 1