Skip to main contentSkip to solution

What will be the output of following query?

SELECT INSTR("Computer Science", "ter");

Solution

✅ Correct Option: 2

INSTR(str, substr) returns the 1-based position where substr first appears in str. Counting the letters of "Computer Science" gives C = 1, o = 2, m = 3, p = 4, u = 5, t = 6, e = 7, r = 8. So "ter" starts at position 6.


Option 1: 5 would be the position if counting started from 0, as in Python. SQL positions start from 1.

Options 3 and 4: INSTR returns 0 when the substring is not found, and -1 is what Python's find() returns. Here "ter" is present, so neither applies.

Keyboard Shortcuts

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