Conditions in Query SQL

Asked

Viewed 65 times

1

Hello, I would need a help, I would like to bring only the employee who does not have the word NR-35 in the table/column functionalscursospd/pdf, my problem is that I have more than one course linked to the same user.

SELECT fd.id,
       fd.nome,
       fd.cpf,
       fd.cursos
FROM   funcionariosdoc AS fd
INNER  JOIN funcionarioscursospdf AS fc
ON     fd.id = fc.id_func
WHERE  fd.cursos LIKE '%NR-35%'
AND    fc.pdf NOT LIKE '%NR-35%'

1 answer

0


Hello, this query solves your problem:

SELECT fd.id,
       fd.nome,
       fd.cpf,
       fd.cursos
FROM   funcionariosdoc AS fd
WHERE  fd.cursos LIKE '%NR-35%'
AND    NOT EXISTS (SELECT 1
        FROM   funcionarioscursospdf AS fc
        WHERE  fd.id = fc.id_func
        AND    fc.pdf LIKE '%NR-35%')

Explaining:

I changed his condition fc.pdf NOT LIKE '%NR-35%' for a query that looks in the employee table LIKE '%NR-35%' and return false if any

  • Thanks, it worked!

Browser other questions tagged

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