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