With SQL, how do you select all the records from a table named "Persons" where the value of the column "FirstName" starts with an "a"?

  1. SELECT * FROM Persons WHERE FirstName LIKE '%a';

  2. SELECT * FROM Persons WHERE FirstName='a' ;

  3. SELECT * FROM Persons WHERE FirstName LIKE 'a%' ;

  4. SELECT * FROM Persons WHERE FirstName='%a%;


Correct Option: C

AI Explanation

To select all the records from a table named "Persons" where the value of the column "FirstName" starts with an "a," you can use the SQL query:

C. SELECT * FROM Persons WHERE FirstName LIKE 'a%';

Explanation:

Option A) SELECT * FROM Persons WHERE FirstName LIKE '%a'; This option is incorrect because the LIKE condition '%a' will match any FirstName that ends with 'a', not those that start with 'a'.

Option B) SELECT * FROM Persons WHERE FirstName='a'; This option is incorrect because it will only select records where the FirstName is exactly equal to 'a', not those that start with 'a'.

Option C) SELECT * FROM Persons WHERE FirstName LIKE 'a%'; This option is correct because the LIKE condition 'a%' will match any FirstName that starts with 'a'.

Option D) SELECT * FROM Persons WHERE FirstName='%a%'; This option is incorrect because the LIKE condition '%a%' will match any FirstName that contains 'a' anywhere in the string, not just at the beginning.

Therefore, the correct answer is C) SELECT * FROM Persons WHERE FirstName LIKE 'a%'.

Find more quizzes: