Skip to main contentSkip to solution

Which of the following functions will perform the same task?

A. MID(string, pos, n)

B. SUB(string, pos, n)

C. SUBSTRING(string, pos, n)

D. SUBSTR(string, pos, n)

Solution

✅ Correct Option: 2

MID(), SUBSTRING() and SUBSTR() are synonyms in MySQL. Each returns nn characters of the string starting from position pos.

For example, MID(’COMPUTER’, 4, 3)\text{MID('COMPUTER', 4, 3)}, SUBSTRING(’COMPUTER’, 4, 3)\text{SUBSTRING('COMPUTER', 4, 3)} and SUBSTR(’COMPUTER’, 4, 3)\text{SUBSTR('COMPUTER', 4, 3)} all return PUT.


B (SUB): there is no SQL string function named SUB, so it cannot perform this task. This is why Options 1, 3 and 4 are wrong.

Keyboard Shortcuts

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