INNER JOIN for more than one field in the same table

Asked

Viewed 35 times

0

I have this structure INNER JOIN 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

Only I need you to also find one more field of the same table, as I do?

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

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

It just didn’t work out.

1 answer

0


You do not need the parenthesis to specify. Do it this way:

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

Or

ON categorias.codigo IN (empresas.categoria, empresas.categoria_2)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.