regexp_like() — SQL Technical Interview Questions & Answers
regexp_like()
regexp_like()
- regexp_like() 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: regexp_like(): 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 regexp_like()
regexp_like() — sample query
-- regexp_like()
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;regexp_like(): create two demo rows, then SELECT qty >= 2 ordered. Say which labels come back.
How to Explain regexp_like() to an Interviewer
LIKE vs REGEXP?
LIKE is % and _ REGEXP is regular expressions