Wildcards — SQL Technical Interview Questions & Answers
Wildcards
Wildcards
- LIKE wildcards: % any string, _ one character. Not * . In REGEXP, . and .* are different. Don’t mix the two languages.
- ESCAPE if you need a literal %: LIKE '%10\%%' ESCAPE '\\' (messy — mention you can escape).
- Trap: * from globbing files.
- On the example next to this theory: Wildcards: create two demo rows, then SELECT qty >= 2 ordered. Say which labels come back.
Technical Interview Tip: LIKE 'A%' and LIKE 'A_ha'. Not *.
Code Examples for Wildcards
Wildcards — sample query
-- Wildcards
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;Wildcards: create two demo rows, then SELECT qty >= 2 ordered. Say which labels come back.
How to Explain Wildcards to an Interviewer
LIKE any characters?
%