Which of the following will retrieve the second and third character from the City column in the Customer table?
(A) SELECT MID(City,2,2);
(B) SELECT SUBSTR(City,2,2);
(C) SELECT LEFT(City,2,2);
(D) SELECT SUBSTRING(City,2,2);
Which of the following will retrieve the second and third character from the City column in the Customer table?
(A) SELECT MID(City,2,2);
(B) SELECT SUBSTR(City,2,2);
(C) SELECT LEFT(City,2,2);
(D) SELECT SUBSTRING(City,2,2);
Solution
MID(), SUBSTR() and SUBSTRING() all use the form function(string, start, length). With start = 2 and length = 2, each returns the 2nd and 3rd characters. For example, if City is 'Delhi', each returns 'el'.
Option (C): LEFT() takes only two arguments, LEFT(string, n), and returns the first n characters from the start. LEFT(City,2,2) has an extra argument and gives an error.
SQL positions start at 1, not 0, so start = 2 means the second character.
Related questions:
2025: 15 May Shift 2
2025: 20 May Shift 1
2026: 13 May Shift 2