What will be the output of the following SQL query?
SELECT MID(“Electronics”, 7);
What will be the output of the following SQL query?
SELECT MID(“Electronics”, 7);
Solution
MID(str, pos) returns the substring starting at position pos and continuing to the end of the string when no length is given. Counting from 1 in "Electronics", position 7 is the letter "o".
| E | l | e | c | t | r | o | n | i | c | s |
|---|---|---|---|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 |
Everything from position 7 onwards is "onics".
Option 1: "Electro" is the first 7 characters, which is what LEFT("Electronics", 7) gives. 7 in MID is a starting position, not a length.
Option 2: "lectron" would need a start position and length, MID("Electronics", 2, 7).
Option 4: "tics" is the last 4 characters, which is what RIGHT("Electronics", 4) gives.
SQL string positions start at 1, not 0.
Related questions:
2026: 26 May Shift 1
2025: 21 May Shift 1
2025: 15 May Shift 2
2025: 15 May Shift 2