You need to display the last names of those employees who have the letter "A" as the second character in their names. Which SQL statement displays the required results?

  1. SELECT last_name FROM EMP WHERE last_name LIKE '_A%';

  2. SELECT last_name FROM EMP WHERE last name ='*A%'

  3. SELECT last_name FROM EMP WHERE last name ='_A%';

  4. SELECT last_name FROM EMP WHERE last name LIKE '*A%'


Correct Option: A
Explanation:

To solve this question, the user needs to know about the SQL SELECT statement and the LIKE operator. The LIKE operator is used to match a character pattern in a string. The underscore (_) represents a single character, while the percent sign (%) represents any number of characters.

Now, let's go through each option and explain why it is right or wrong:

A. SELECT last_name FROM EMP WHERE last_name LIKE '_A%'; This option is correct. It selects the last names of employees from the EMP table where the last name has any character as the first character and "A" as the second character, followed by any number of characters.

B. SELECT last_name FROM EMP WHERE last name ='A%' This option is incorrect because the equal sign (=) is used for exact matches, and the asterisk () is not a valid wildcard character in SQL.

C. SELECT last_name FROM EMP WHERE last name ='A%'; This option is incorrect because the equal sign (=) is used for exact matches, and the underscore () represents only a single character, not any number of characters.

D. SELECT last_name FROM EMP WHERE last name LIKE 'A%' This option is incorrect because the percent sign (%) is used to match any number of characters, not the asterisk ().

Therefore, the correct answer is:

The Answer is: A. SELECT last_name FROM EMP WHERE last_name LIKE '_A%';

Find more quizzes: