SQL traps · SQL

SQL: 'abc' = 'ABC' is 0... but LIKE says 1?!PRO

In SQLite = compares exactly, LIKE ignores case for A–Z. COLLATE NOCASE or lower() makes it explicit.

-- SQL: 'abc' = 'ABC' is 0 ... but LIKE says 1 ?!
-- In SQLite, = compares exactly (case matters), while LIKE ignores case for A–Z.
SELECT 'abc' = 'ABC';                      -- 0 ?!
SELECT 'abc' LIKE 'ABC';                   -- 1 ?!

-- Fix: say what you mean
SELECT 'abc' = 'ABC' COLLATE NOCASE;       -- 1 ✓ case-insensitive equals
SELECT lower('ABC') = 'abc';               -- 1 ✓
Open code S3 in Pocket Compiler Download the Pocket Compiler app — free

No app yet? Install it, then open the app and type the code S3 in Code Library.