LIKE with strange behavior in MYSQL

Asked

Viewed 49 times

0

I have the following query

SELECT p.nome_completo, p.id_pessoa, curr.link_video, prof.nome as nome_profissao, fav.id_favorito as fav_id
FROM candidato as cand
INNER JOIN pessoa as p on (p.id_pessoa = cand.fk_pessoa)
INNER JOIN curriculo as curr on (cand.id_candidato = curr.fk_candidato)
INNER JOIN curriculo_has_profissao as chp on (curr.id_curriculo = chp.fk_id_curriculo)
INNER JOIN profissao as prof on (chp.fk_id_profissao = prof.id_profissao)
LEFT JOIN empregador_has_favorito_curriculo as efc on (efc.fk_id_curriculo = curr.id_curriculo)
LEFT JOIN favorito as fav on (fav.id_favorito = efc.fk_id_favorito)
WHERE prof.nome LIKE '%Abastecedor de Linha de Produção%' OR prof.nome LIKE '%Abastecedor de Máquinas%'
AND curr.fk_status_curriculo = 2

The idea is to bring all candidates when searching for a profession by name. I am using LIKE in case looking for Professor Return all types of registered teachers..

the strange thing about this query is that when I perform it, returns a result, with the profession Abastecedor de Linha de Produção, but if I remove the OR, leaving only the first clause of WHERE, should return the same result, since the profession is the same. But no, does not return any resutlado. I also tested exchange for '%Abastecedor%' to see if it would return any results, but also returned nothing.

Any idea ?

  • 1

    Could be something related to the origin of the logical operators, I tried to put the clauses of or in brackets.

  • That’s not the point, the problem is with the OR he finds results with the profession Abastecedor de Linha de Produção, as in the query. The problem is when I leave only the prof.nome LIKE '%Abastecedor de Linha de Produção%' should return a result, but does not return

1 answer

1


The point is this AND. Probably its result as a 'production line supplier' does not have Curr.fk_status... equal to 2. When you put the or, it intepreta like this:

prof.nome like 'supplier.. ' OR (prof.nome like 'supplier' and Curr.status = 2)

Take the end and take the test.

Browser other questions tagged

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