SQL Quest › SQL Interview Questions › String Functions
Position of '@' in Email (INSTR)
A data-quality probe wants the position of the '@' character in each customer email — anything <= 0 would indicate a malformed address.
Show customer_id, email, and at_pos (INSTR(email, '@')). Order by customer_id.
INSTR(haystack, needle) returns the 1-indexed position of the first match, or 0 if the needle isn't found. It's the SQL equivalent of str.indexOf() in most programming languages, but with 1-based indexing.
Solve it in the browser editor →
Runs on SQLite in your browser, graded against the expected result, no signup. A wrong answer gets a diagnosis, not just "incorrect".
Schema
customers
| customer_id | name | signup_date | membership | total_orders | |
|---|---|---|---|---|---|
| 1 | John Smith | john.smith@email.com | 2023-01-15 | Gold | 15 |
| 2 | Emma Wilson | emma.wilson@email.com | 2023-03-20 | Silver | 8 |
| 3 | Michael Brown | michael.brown@email.com | 2023-02-10 | Gold | 12 |
Expected output: at_pos = 11
Hint
SELECT, INSTR, String Functions, and open the hint there if you stall.Concepts
SELECT INSTR String Functions
Practise the topic: SQL practice questions · String function practice
In these company practice sets
A SQL Quest challenge matched to patterns reported for these companies — not a question any of them has published.
Related questions
Where would this cost you points in an interview?
Ten questions, no signup: a Skillmap across nine SQL skills and the one to fix first.
Take the readiness test