CompTIA Tech+ (FC0-U71)Data and Database FundamentalsMedium
A technician needs to write a SQL query that returns all customers whose last name begins with the letter 'S'. Which clause and operator should be used?
- AWHERE LastName BETWEEN 'A' AND 'S'
- BORDER BY LastName ASC
- CWHERE LastName LIKE 'S%'
- DWHERE LastName = 'S'
Show answer & explanationAnswer & explanation
Correct answer: C. WHERE LastName LIKE 'S%'
The LIKE operator with the wildcard % allows pattern matching, so 'S%' matches any value that starts with the letter S followed by any number of characters. This is the standard way to filter text data based on a partial match in SQL.
Why the other options are wrong
- A. BETWEEN would return a range of alphabetically sorted names but not specifically only those starting with S.
- B. ORDER BY only sorts results and does not filter which rows are returned.
- D. An equals sign requires an exact match, so it would only return rows where LastName is exactly the single character 'S'.
SQL LIKE Operator
A SQL operator used in a WHERE clause to search for a specified pattern in a text column, often combined with wildcard characters.
- % represents zero or more characters
- _ represents exactly one character
- Used with WHERE to filter partial text matches
Memory trick: LIKE plus percent sign is like a search net catching anything after the S.