Home > Software engineering >  How can I get SQL query result except one specific row?
How can I get SQL query result except one specific row?

Time:12-10

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

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

CodePudding user response:

Try this;

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

See Demo

CodePudding user response:

You can try this;

SELECT * FROM personnels 
WHERE Name != "John" and Department != "Computer"
  • Related