Not Equal — SQL Technical Interview Questions & Answers

Not Equal

Not Equal

  • Not equal is <> or != . WHERE marks <> 0; MySQL accepts both. Standard SQL prefers <>. NULL <> 0 is not true — use IS NOT NULL as well if you need rows with a value that is not 0.
  • Trap: marks != NULL. Use IS NOT NULL.
  • On the example next to this theory: Not Equal: create two demo rows, then SELECT qty >= 2 ordered. Say which labels come back.

Technical Interview Tip: WHERE marks <> 40; never != NULL.

Code Examples for Not Equal

Not Equal — sample query

-- Not Equal
CREATE TABLE demo (
  id INTEGER PRIMARY KEY,
  label TEXT NOT NULL,
  qty INTEGER DEFAULT 0
);
INSERT INTO demo (id, label, qty) VALUES
  (1, 'alpha', 2),
  (2, 'beta', 5);
SELECT label, qty FROM demo WHERE qty >= 2 ORDER BY qty DESC;

Not Equal: create two demo rows, then SELECT qty >= 2 ordered. Say which labels come back.

How to Explain Not Equal to an Interviewer

Not equal operator?

<> or != NULL needs IS NOT NULL