Inner Join with Where and multiple tables

1

I'm setting up a query, where I need to join between two tables (since the data will be in the main B but not in the BC complement) and a third table that I need the data, which will always be in the main table B.

I tried as below, but returns syntax error. I searched right here and did not find an example, any suggestions?

select DATE_FORMAT(b.dt_lancamento, '%d-%m-%Y') as dt_lancamento_F,
                      DATE_FORMAT(b.dt_abertura, '%d-%m-%Y') as dt_abertura_F,
                      DATE_FORMAT(b.dt_finalizacao, '%d-%m-%Y') as dt_finalizacao_F,
                      DATE_FORMAT(b.dt_prim_producao, '%d-%m-%Y') as dt_prim_producao_F,
                      DATE_FORMAT(bc.dt_solicitacao, '%d-%m-%Y') as dt_solicitacao_F,
                      DATE_FORMAT(bc.dt_alergenico_ti, '%d-%m-%Y') as dt_alergenico_ti_F,
                      DATE_FORMAT(bc.dt_auto_avaliacao_ti, '%d-%m-%Y') as dt_auto_avaliacao_ti_F,
                      DATE_FORMAT(bc.dt_cert_halal, '%d-%m-%Y') as dt_cert_halal_F,
                      DATE_FORMAT(bc.dt_cert_kosher, '%d-%m-%Y') as dt_cert_kosher_F,
                      DATE_FORMAT(bc.dt_cert_brc, '%d-%m-%Y') as dt_cert_brc_F,
                      DATE_FORMAT(bc.dt_cert_fssc, '%d-%m-%Y') as dt_cert_fssc_F,
                      DATE_FORMAT(bc.dt_cert_ifs, '%d-%m-%Y') as dt_cert_ifs_F,
                      DATE_FORMAT(bc.dt_controle_pragas, '%d-%m-%Y') as dt_controle_pragas_F,
                      DATE_FORMAT(bc.dt_apro_fornecedor, '%d-%m-%Y') as dt_apro_fornecedor_F
                      u.admin NIVEL, BC.*,B.*
                 FROM USUARIOS U,
                      BRIEFING B
                LEFT JOIN BRIEFING_COMPRAS BC ON bc.cod = b.cod
                WHERE B.responsavel = u.nome_completo
                  AND B.COD = 551
    
asked by anonymous 05.11.2018 / 20:53

1 answer

4

A comma was missing after one of the fields was declared:

SELECT DATE_FORMAT(b.dt_lancamento, '%d-%m-%Y') as dt_lancamento_F,
       DATE_FORMAT(b.dt_abertura, '%d-%m-%Y') as dt_abertura_F,
       DATE_FORMAT(b.dt_finalizacao, '%d-%m-%Y') as dt_finalizacao_F,
       DATE_FORMAT(b.dt_prim_producao, '%d-%m-%Y') as dt_prim_producao_F,
       DATE_FORMAT(bc.dt_solicitacao, '%d-%m-%Y') as dt_solicitacao_F,
       DATE_FORMAT(bc.dt_alergenico_ti, '%d-%m-%Y') as dt_alergenico_ti_F,
       DATE_FORMAT(bc.dt_auto_avaliacao_ti, '%d-%m-%Y') as dt_auto_avaliacao_ti_F,
       DATE_FORMAT(bc.dt_cert_halal, '%d-%m-%Y') as dt_cert_halal_F,
       DATE_FORMAT(bc.dt_cert_kosher, '%d-%m-%Y') as dt_cert_kosher_F,
       DATE_FORMAT(bc.dt_cert_brc, '%d-%m-%Y') as dt_cert_brc_F,
       DATE_FORMAT(bc.dt_cert_fssc, '%d-%m-%Y') as dt_cert_fssc_F,
       DATE_FORMAT(bc.dt_cert_ifs, '%d-%m-%Y') as dt_cert_ifs_F,
       DATE_FORMAT(bc.dt_controle_pragas, '%d-%m-%Y') as dt_controle_pragas_F,
       DATE_FORMAT(bc.dt_apro_fornecedor, '%d-%m-%Y') as dt_apro_fornecedor_F,
       u.admin NIVEL,
       BC.*,
       B.*
  FROM USUARIOS U
 INNER JOIN BRIEFING B ON B.responsavel = u.nome_completo
  LEFT JOIN BRIEFING_COMPRAS BC ON bc.cod = b.cod
 WHERE B.COD = 551
    
05.11.2018 / 20:58