With SQL, how do you select all the records from a table named 'Persons' where the value of the column 'FirstName' is 'Peter'?

  1. SELECT * FROM Persons WHERE FirstName <> 'Peter'

  2. SELECT [all] FROM Persons WHERE FirstName='Peter'

  3. SELECT [all] FROM Persons WHERE FirstName LIKE 'Peter'

  4. SELECT * FROM Persons WHERE FirstName='Peter'


Correct Option: D
Explanation:

To select all the records from the table named 'Persons' where the value of the column 'FirstName' is 'Peter', the correct SQL query is:

D. SELECT * FROM Persons WHERE FirstName='Peter'

Let's go through each option and explain why the other options are incorrect:

A. SELECT * FROM Persons WHERE FirstName <> 'Peter' This query selects all records where the 'FirstName' column is not equal to 'Peter'. It is the opposite of what we want, so this option is incorrect.

B. SELECT [all] FROM Persons WHERE FirstName='Peter' The use of '[all]' is not necessary in this query. It should be replaced with '*' to select all columns. Additionally, the operator '=' should be used instead of 'LIKE' since we are looking for an exact match. Therefore, this option is incorrect.

C. SELECT [all] FROM Persons WHERE FirstName LIKE 'Peter' The 'LIKE' operator is used for pattern matching and allows the use of wildcards (% or _). Since we are looking for an exact match of 'Peter', the '=' operator should be used instead. Therefore, this option is incorrect.

D. SELECT * FROM Persons WHERE FirstName='Peter' This option correctly selects all records from the 'Persons' table where the 'FirstName' column is equal to 'Peter'.

So, the correct answer is: D. SELECT * FROM Persons WHERE FirstName='Peter'

Find more quizzes: