IS NOT NULL — SQL Technical Interview Questions & Answers

IS NOT NULL

IS NOT NULL

  • WHERE marks IS NOT NULL; rows that actually have a marks value (including 0). Use it when you want ‘exam written’ vs ‘absent’.
  • COUNT(marks) is similar to counting IS NOT NULL on that column.
  • Trap: IS NOT NULL and then still using the column in a way that assumes it cannot be 0.
  • On the example next to this theory: IS NOT NULL: create two demo rows, then SELECT qty >= 2 ordered. Say which labels come back.

Technical Interview Tip: WHERE marks IS NOT NULL;

Code Examples for IS NOT NULL

IS NOT NULL — sample query

-- IS NOT NULL
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;

IS NOT NULL: create two demo rows, then SELECT qty >= 2 ordered. Say which labels come back.

How to Explain IS NOT NULL to an Interviewer

IS NOT NULL vs > 0?

IS NOT NULL includes 0 > 0 drops zeros