What is the purpose of the LIKE operator?
A
To compare numeric values B
To test for NULL values C
To search for a specified pattern in a column D
To sort query results
Analysis & Theory
LIKE is used to search for patterns in text columns.
Which wildcard character represents zero or more characters?
A
_ (underscore) B
% (percent sign) C
? D
*
Analysis & Theory
% matches any sequence of characters (including no characters).
Which wildcard character matches exactly one character?
A
% B
_ C
* D
#
Analysis & Theory
_ matches exactly one character.
Which query finds all customers whose names start with 'A'?
A
SELECT * FROM customers WHERE name LIKE '%A'; B
SELECT * FROM customers WHERE name LIKE 'A%'; C
SELECT * FROM customers WHERE name LIKE '_A'; D
SELECT * FROM customers WHERE name LIKE '%A%';
Analysis & Theory
'A%' means the value starts with 'A' followed by any characters.
What does this query return?
SELECT * FROM products WHERE name LIKE '%book%';
A
Names starting with 'book' B
Names ending with 'book' C
Names containing 'book' anywhere D
Names equal to 'book'
Analysis & Theory
'%book%' matches any name containing 'book' in any position.
Which query finds all employees with a 5-letter name?
A
SELECT * FROM employees WHERE name LIKE '_____'; B
SELECT * FROM employees WHERE name LIKE '%%%%%'; C
SELECT * FROM employees WHERE name LIKE '____'; D
SELECT * FROM employees WHERE name LIKE '_%';
Analysis & Theory
Each underscore represents one character, so 5 underscores = 5 letters.
What does this query do?
SELECT * FROM users WHERE username LIKE 'A_%';
A
Finds usernames starting with 'A' and any number of characters B
Finds usernames starting with 'A' followed by exactly one character C
Finds usernames ending with 'A' D
Finds usernames containing 'A' anywhere
Analysis & Theory
'A_' means 'A' followed by exactly one character.
Which operator can be used instead of LIKE for more complex pattern matching?
A
BETWEEN B
REGEXP C
IN D
EXISTS
Analysis & Theory
REGEXP (or RLIKE) supports regular expressions for advanced patterns.
What does this query return?
SELECT * FROM orders WHERE order_code LIKE '__5%';
A
Order codes that have '5' in the second position B
Order codes that start with '5' C
Order codes where the third character is '5' D
Order codes ending with '5'
Analysis & Theory
Two underscores skip the first two characters, then '5' is the third character.
How do you search for values ending with 'ing'?
A
LIKE 'ing%' B
LIKE '%ing' C
LIKE '%ing%' D
LIKE '_ing'
Analysis & Theory
'%ing' matches any string ending with 'ing'.