String — SQL Technical Interview Questions & Answers
String
String
- String functions work on VARCHAR/CHAR/TEXT: CONCAT, SUBSTR, TRIM, UPPER, LENGTH. SELECT UPPER(name), TRIM(city) FROM students;
- They return a new value. The table does not change until UPDATE. Indexes start at 1.
- LENGTH is bytes; CHAR_LENGTH is characters (utf8mb4). CONCAT with NULL becomes NULL unless you use CONCAT_WS or IFNULL.
- Trap: using string functions in WHERE on a huge indexed column (UPPER(name) = 'ASHA' may skip the index). Prefer storing canonical form.
- On the example next to this theory: String: create two demo rows, then SELECT qty >= 2 ordered. Say which labels come back.
Technical Interview Tip: Name CONCAT / TRIM / UPPER and one students example.
Code Examples for String
String — sample query
-- String
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;String: create two demo rows, then SELECT qty >= 2 ordered. Say which labels come back.
How to Explain String to an Interviewer
Name three string functions.
CONCAT TRIM UPPER