Hint: Count characters carefully starting at 1 [OK]
Common Mistakes:
Starting count at 0
Extracting wrong number of characters
Confusing underscore with letter
4. Identify the error in the SQL query: SELECT SUBSTRING('Database', 0, 4);
medium
A. Start position cannot be zero
B. Length cannot be less than 5
C. String must be in double quotes
D. SUBSTRING requires only two parameters
Solution
Step 1: Check SUBSTRING start position rules
In SQL, string positions start at 1, not 0.
Step 2: Analyze given query
Start position is 0, which is invalid and causes an error.
Final Answer:
Start position cannot be zero -> Option A
Quick Check:
Positions start at 1, zero is invalid [OK]
Hint: Start counting at 1, never zero [OK]
Common Mistakes:
Using zero as start position
Confusing string quotes
Wrong number of parameters
5. You have a column product_code with values like 'AB12345XYZ'. Write a SQL query to extract the numeric part (5 digits) starting from position 3. Which query correctly extracts '12345'?
hard
A. SELECT SUBSTRING(product_code, 4, 5) FROM products;
B. SELECT SUBSTRING(product_code, 3, 5) FROM products;
C. SELECT SUBSTRING(product_code, 3, 4) FROM products;
D. SELECT SUBSTRING(product_code, 2, 5) FROM products;