INNER JOIN for more than one field in the same table

0

I have this INNER JOIN structure that works perfectly for what I needed so far.

SELECT categorias.codigo,categorias.categoria,categorias.slug,empresas.cidade
    FROM categorias
    INNER JOIN
    empresas
    ON categorias.codigo = empresas.categoria
    WHERE empresas.cidade = '100'
    GROUP BY categorias.categoria

I just need to filter another field from the same table, how do I?

Example, I have the following line: ON categorias.codigo = empresas.categoria I need it to also compare the categoria_2 How do I?

ON categorias.codigo = (empresas.categoria OR categorias.codigo = empresas.categoria_2)

It just did not work out.

    
asked by anonymous 30.11.2018 / 17:27

1 answer

0

You do not need the parentheses to specify. Do as follows:

ON categorias.codigo = empresas.categoria
OR categorias.codigo = empresas.categoria_2

Or

ON categorias.codigo IN (empresas.categoria, empresas.categoria_2)
    
30.11.2018 / 17:30