Multiple choice technology databases

Which of the following queries can you use to search for employees with the pattern 'A_B' in their names?

  1. SELECT last_name FROM employees WHERE last_name LIKE '%A_B%' ESCAPE '\';

  2. SELECT last_name FROM employees WHERE last_name LIKE '%A_B%' ESCAPE;

  3. SELECT last_name FROM employees WHERE last_name LIKE 'A_B%' ESCAPE '%';

  4. SELECT last_name FROM employees WHERE last_name LIKE '%A_B%' ESCAPE '';

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

To search for the literal pattern 'A_B' (where underscore is a literal character, not a wildcard), use LIKE '%A_B%' ESCAPE '\'. The ESCAPE clause specifies that backslash is the escape character, so _ treats underscore as a literal. Option A uses double backslash incorrectly. Options B and C have wrong ESCAPE syntax - missing escape character or using % incorrectly.