3
I have a select that returns some data from the database, but I need this select to return the values only when in a group of values, there is the value x
SELECT pessoas.id AS ID,
pessoas.nom_pessoa AS nome,
pessoas.cod_sexo_pes AS sexo,
YEAR(FROM_DAYS(TO_DAYS(NOW())-TO_DAYS(pessoas.dta_nasc_pes))) AS idade,
CASE WHEN pessoas.cod_cert_civ_pes !='' THEN '--' ELSE 'Não' end AS RN,
CASE WHEN pessoas.num_rg_pes !='' THEN '--' ELSE 'Não' end AS RG,
CASE WHEN pessoas.num_nis_pes !='' THEN '--' ELSE 'Não' end AS NIS,
CASE WHEN pessoas.num_cpf_pes !='' THEN '--' ELSE 'Não' end AS CPF,
CASE WHEN pessoas.num_cart_trab_pes !='' THEN '--' ELSE 'Não' end AS CP,
CASE WHEN pessoas.num_tit_eleit_pes !='' THEN '--' ELSE 'Não' end AS Titulo,
familia_domicilio.nom_local_fam AS bairro
FROM pessoas
INNER JOIN familia_domicilio ON familia_domicilio.id = pessoas.cod_familia
WHERE
familia_domicilio.nom_local_fam = 'AGUAS ESPRAIADAS'
AND YEAR(FROM_DAYS(TO_DAYS(NOW())-TO_DAYS(pessoas.dta_nasc_pes))) BETWEEN '1' AND '100';
In this case, I would like the select me to return the selected values, only if there was at least one "No" value between the people columns.cod_cert_civ_pes/ people.num_rg_pes /people.num_nis_pes / people.num_cpf_pes / people.num_cart_trab_pes / people..
Not just using the OR operator?
– mau humor
What part of the code would the OR use?
– user46464
...WHERE (people.num_nis_pes = 'No' OR people.num_cpf_pes='No' OR... and so on ....
– mau humor
It worked, thank you very much my dear
– user46464
@user46464 if the AND of the above comment solved, it is the case of using IN to simplify
– Bacco