Not regexp Operator — SQL Technical Interview Questions & Answers
Not regexp Operator
Not regexp Operator
- Not regexp Operator is pattern matching. LIKE uses % and _. REGEXP / RLIKE uses regular expressions (e.g. name REGEXP '^[A-Z]'). They are not interchangeable.
- REGEXP_LIKE, REGEXP_REPLACE, REGEXP_SUBSTR, REGEXP_INSTR are MySQL 8 helpers. Don’t write Java-style /pattern/g.
- Trap: LIKE with regex stars. Trap: REGEXP on a huge unindexed column.
- On the example next to this theory: Not regexp Operator: create two demo rows, then SELECT qty >= 2 ordered. Say which labels come back.
Technical Interview Tip: LIKE vs REGEXP in one sentence, plus one example.
Code Examples for Not regexp Operator
Not regexp Operator — sample query
-- Not regexp Operator
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 regexp Operator: create two demo rows, then SELECT qty >= 2 ordered. Say which labels come back.
How to Explain Not regexp Operator to an Interviewer
LIKE vs REGEXP?
LIKE is % and _ REGEXP is regular expressions