61.0k views
3 votes
You need to write a query that returns all Employees that have a LastName starting with the letter A. Which WHERE clause should you use to fill in the blank in this query?

a) WHERE LastName LIKE 'A%'
b) WHERE LastName = 'A%'
c) WHERE LastName LIKE '%A%'
d) WHERE LastName = '%A%'

1 Answer

3 votes

Final answer:

The correct WHERE clause to find all employees with a last name starting with 'A' is 'WHERE LastName LIKE 'A%''. The LIKE operator with '%' wildcard effectively matches any last names beginning with 'A'.

Step-by-step explanation:

The student's query requires finding all employees with a last name starting with the letter 'A'. The correct choice for the WHERE clause in SQL to achieve this would be option a) WHERE LastName LIKE 'A%'. This is because the LIKE operator is used to search for a specified pattern in a column. Here '%' acts as a wildcard character, matching any sequence of characters. Therefore, 'A%' will match any last name starting with 'A' followed by any combination of characters.

Option b) WHERE LastName = 'A%' is incorrect because the equals sign is a literal comparison operator, and will not treat '%' as a wildcard. Option c) WHERE LastName LIKE '%A%' would return last names that contain 'A' at any position, and option d) WHERE LastName = '%A%' would mistakenly attempt a literal comparison including the wildcard characters which SQL does not allow.

User Tikhon
by
8.0k points
Welcome to QAmmunity.org, where you can ask questions and receive answers from other members of our community.