Multiple choice technology databases

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<'Pettersen'

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

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

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

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

The BETWEEN operator in SQL is inclusive and selects values within a range. Option B correctly uses BETWEEN 'Hansen' AND 'Pettersen' to get all LastNames alphabetically from Hansen through Pettersen. Option A uses > and < which would exclude the boundary values, and Options C and D have incorrect syntax or operators.