QuestionQ17

VerifiedRestricting and Sorting Data

Review the structure of the CUSTOMERS table shown below:

Question Image

You need to write a query that returns details of all customers whose city name begins with the letter D and has at least two more characters following it.

Which query should you use?

Explanation

In SQL, the LIKE operator is used for pattern matching with wildcard characters: the underscore () represents exactly one character, and the percent sign (%) represents zero or more characters. Using LIKE 'D%' matches any CITY value that starts with 'D', followed by at least one required character (matched by ), and then zero or more additional characters (matched by %) — correctly filtering for cities beginning with D that have additional characters after it. The '=' operator (used in options B and D) does not interpret '' or '%' as wildcards; it performs an exact string comparison, so those queries would only match a literal string containing a percent sign or underscore character, not perform pattern matching. Option C ('D_') restricts results to exactly two-character city names starting with D, which is overly restrictive and does not allow for city names longer than two characters.

Community Discussion

No comments yet. Be the first to start the discussion!