With SQL, how do you select all the records from a table named "Persons" where the "LastName" is alphabetically between (and including) "Hansen" and "Pettersen"?

  1. SELECT * FROM Persons WHERE LastName>'Hansen' AND LastName

  2. SELECT * FROM Persons WHERE LastName BETWEEN 'Hansen' AND 'Pettersen'

  3. SELECT LastName>'Hansen' AND LastName

  4. SELECT LastName<>'Hansen' AND LastName<>'Pettersen' FROM Persons


Correct Option: B
Explanation:

To solve this question, the user needs to know the syntax for the SELECT statement in SQL and how to use the WHERE clause to filter records based on a specific condition. The user must also understand the BETWEEN operator in SQL that is used to select values within a range.

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

A. SELECT * FROM Persons WHERE LastName>'Hansen' AND LastName'Hansen' AND LastName'Hansen' AND LastName<>'Pettersen' FROM Persons This option is incorrect. The query selects all the records except the records with the last name "Hansen" and "Pettersen" from the "Persons" table, which is not what we want. We need to select records with last name between (and including) "Hansen" and "Pettersen".

The Answer is: B

Find more quizzes: