First, you do not need the final LEFT JOIN
. You have the condition TRA.RAZAO = 'Google'
in the WHERE
clause. This effective turns the LEFT JOIN
into an inner join.
The most important thing, though, is the join
condition:
LEFT JOIN DBCLIENTE TRA ON DBSMP.ID_TRANSPORTADOR = CLI.ID_CLIENTE
In other words, your query does not make sense. You are joining in a table with no reference to the table. I am not sure what the right fix is, because you don't give enough information. My best guess is that this is what you mean for the from
clause:
FROM DBSMP_WORK WORK
INNER JOIN DBSMP ON WORK.ID_SMP = DBSMP.ID_SMP
INNER JOIN DBCLIENTE CLI ON DBSMP.ID_CLIENTE = CLI.ID_CLIENTE
LEFT JOIN DBCLIENTE TRA ON TRA.ID_TRANSPORTADOR = CLI.ID_CLIENTE