Back to SQL Notes
Topic #84

SQL NOT Operator

NOT reverses a condition — it returns rows where the condition is false.

Syntax

WHERE NOT condition

Sample Table: employees

namedepartment
AmanEngineering
RiyaMarketing
NehaDesign

Example

SELECT name FROM employees
WHERE NOT department = 'Engineering';

Equivalent, and usually more readable:

SELECT name FROM employees
WHERE department <> 'Engineering';

Output: Riya, Neha.

NOT with IN, BETWEEN, LIKE, IS NULL

WHERE department NOT IN ('Engineering', 'Design')
WHERE salary NOT BETWEEN 50000 AND 70000
WHERE name NOT LIKE 'A%'
WHERE manager_id IS NOT NULL

These forms are usually clearer than wrapping the whole expression in NOT (...).

Practical Use Case

Excluding a specific set of rows is often easier to express with NOT than by listing every value you do want — e.g. "every department except Engineering" is one condition instead of enumerating the rest.

Common Mistakes

  • NOT and NULL don't mix the way people expect. WHERE NOT department = 'Engineering' will silently exclude rows where department is NULL — NULL never satisfies = or its negation. If you need NULLs included, handle them explicitly.
  • Writing deeply nested NOT (A AND NOT B) logic instead of simplifying it first — hard to read and easy to get wrong

Interview Relevance

Q: "Does WHERE NOT department = 'Engineering' return rows where department is NULL?" No — and explaining why (three-valued logic: NULL comparisons return UNKNOWN, not TRUE) is a strong signal in an interview.

Practice Question

Write a query for all employees NOT in the "Design" or "Marketing" departments, using NOT IN.

Want to go beyond the notes?

Join Coding Now Tech Institute's SQL course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

SQL NOT Operator – FAQs

Quick answers about learning SQL NOT Operator in SQL.

This free note from Coding Now Tech Institute explains SQL NOT Operator in SQL — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every SQL topic on Coding Now Tech Institute, including SQL NOT Operator, is 100% free with no signup required.
With focused practice, most students grasp SQL NOT Operator in 1–3 days from these notes; pairing it with Coding Now Tech Institute's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the Coding Now Tech Institute Community (/community) — expert instructors answer within 24 hours.
Call NowEnroll Now