SQL QuestSQL Interview Questions › String Functions

Position of '@' in Email (INSTR)

EasyFreeQuerying BasicsString Functions

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_idnameemailsignup_datemembershiptotal_orders
1John Smithjohn.smith@email.com2023-01-15Gold15
2Emma Wilsonemma.wilson@email.com2023-03-20Silver8
3Michael Brownmichael.brown@email.com2023-02-10Gold12

Expected output: at_pos = 11

Hint

The hint for this one spells out most of the query, so it stays in the editor. Reach for 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

Plaid

A SQL Quest challenge matched to patterns reported for these companies — not a question any of them has published.

Related questions

Long-Named PassengersEasy · FreeEmployee Display Cards (Concat)Easy · FreeCountry Codes in UppercaseEasy · FreeExtract Family Names (SUBSTR + INSTR)Easy · FreeYear Code from Order Date (SUBSTR)Easy · FreeMovie Title Initial Letter Histogram (SUBSTR)Easy · Free

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