Query with NOT IN in mysql

Asked

Viewed 35 times

0

I have 2 tables (function and function_situation). I need to bring in the employees in their proper situations.

The big x of the question is not to bring in some employees who are in some situations (exception).

I have this query, but it keeps displaying the codes I don’t want to appear.

Where am I going wrong?

SELECT DISTINCT 
    a.funcionario_situacao, 
    b.funcionariosituacao_title AS title 
FROM (".DB_FUNCIONARIO." a 
JOIN ".DB_FUNCIONARIOSITUACAO." b ON a.funcionario_situacao = b.funcionariosituacao_id)
WHERE a.funcionario_situacao NOT IN (:excecao)
ORDER BY b.funcionariosituacao_title ASC", "excecao=1,2,3,4,5,14,15"
  • it would be good to put the structure of the tables, which helps when viewing your problem

1 answer

0

I didn’t see any big problems in her query, she just didn’t bring an employee’s name or id, and I removed a parentheses from/John that I believe shouldn’t be there. Check the result:

SELECT DISTINCT 
    a.funcionario_nome,
    a.funcionario_situacao, 
    b.funcionariosituacao_title AS title 
FROM DB_FUNCIONARIO a 
INNER JOIN DB_FUNCIONARIOSITUACAO b ON a.funcionario_situacao = b.funcionariosituacao_id
WHERE a.funcionario_situacao NOT IN (1,2,3,4,5,14,15)
ORDER BY b.funcionariosituacao_title ASC

Browser other questions tagged

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