Skip to main contentSkip to solution

Which of the following is the correct query to retrieve the last three characters from the 'City' column of the 'Customer' table?

A. SELECT LEFT(City, 3) FROM Customer;

B. SELECT RIGHT(City, 3) FROM Customer;

C. SELECT MID(City, 3) FROM Customer;

D. SELECT LENGTH(City, 3) FROM Customer;

Solution

✅ Correct Option: 2

RIGHT(string, n) returns the last nn characters of a string. So RIGHT(City, 3) gives the last three characters of every value in the 'City' column.


Option A (LEFT(City, 3)): returns the first three characters, not the last three.

Option C (MID(City, 3)): starts at position 3 and returns everything from there to the end of the string, so it is not fixed at three characters.

Option D (LENGTH(City, 3)): LENGTH() takes one argument and only returns the length of the string.

LEFT() and RIGHT() work as a pair, taking characters from the start and the end respectively.

Keyboard Shortcuts

  • Left arrow: Previous question
  • Right arrow: Next question
  • S key: Jump to solution
  • Q key: Jump to question