Which MySQL Statement Fails: SELECT 1, 2, 3 vs SELECT 1 2 3 vs SELECT '1 2 3'
Company: Verisk
Role: Data Scientist
Category: Data Manipulation (SQL/Python)
Difficulty: easy
Interview Round: Online Assessment
An online assessment includes this multiple-choice question. Each option is a complete statement run on its own in MySQL.
Select the expression that causes a MySQL error.
- **A.** `SELECT 1, 2, 3`
- **B.** `SELECT 1 2 3`
- **C.** `SELECT '1 2 3'`
- **D.** None of the above; all expressions are correct.
Choose one option, and explain what MySQL does with each of the others.
```hint What may follow a value
Once the parser has read a complete value after `SELECT`, ask which kinds of token it can accept next.
```
```hint Inside and outside quotes
Compare what the parser sees between quotation marks with what it sees without them.
```
### Clarifying Questions
- Is each option executed by itself, with no `FROM` clause and no surrounding statement?
- Does "causes an error" mean the server rejects the statement, as opposed to running it with a warning or an unexpected result?
- Should MySQL's default SQL mode be assumed, or a mode such as `ANSI_QUOTES` that changes how quotation marks are read?
### What a Strong Answer Covers
- The failing option, with the parsing reason it fails rather than a guess
- What options A and C each return: how many columns, and what values
- Why "none of the above" is wrong
- How MySQL's optional `AS` keyword decides which missing-comma mistakes fail and which run silently
### Follow-up Questions
- `SELECT price quantity FROM orders` runs without an error. What does it return, and why is that harder to catch than option B?
- What do `SELECT 1 'total'` and `SELECT '1' '2' '3'` return in MySQL?
- Would option B also fail in PostgreSQL, and how do the two statements in the previous follow-up behave there?
Overview: A multiple-choice MySQL question asks which of SELECT 1, 2, 3, SELECT 1 2 3 and SELECT '1 2 3' causes an error. It tests how MySQL parses a select list, where column aliases with an optional AS keyword are allowed, and how string literals differ from bare numbers.
Read the full Verisk Data Scientist interview experience this question came from