Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can I get SQL query result except one specific row?

I have a personnel table. I want to get all records in this table except which has IT value as department and name is John.

These are my rows:

Name Department
John Computer
John IT
Kevin Medical
Kevin IT
Kevin Pharmacy

This is my query

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

select * 
from personnels per 
where (per.Name = 'John' and per.Department <> 'IT')

This is the result of that query:

Name Department
John Computer

Expected result

Name Department
John Computer
Kevin Medical
Kevin IT
Kevin Pharmacy

>Solution :

Try this;

SELECT * 
FROM personnels per
WHERE NOT (per.Name = 'John' AND per.Department = 'IT')

See Demo

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading