mpen
mpen

Reputation: 283043

Why must the asterisk come first?

In MySQL, select *,1 from t appears to be valid, but select 1,* from t is not.

  1. Why is that?
  2. Is there any official documentation on this? I can't find anything that says the latter is invalid, and the error message I get doesn't say anything specifically about it either.

Upvotes: 3

Views: 148

Answers (1)

sjagr
sjagr

Reputation: 16502

From the MySQL docs, you are told what you can do with the unqualified *:

A select list consisting only of a single unqualified * can be used as shorthand to select all columns from all tables:

SELECT * FROM t1 INNER JOIN t2 ...

The pertinent documentation you're looking for is two bullet points below that:

Use of an unqualified * with other items in the select list may produce a parse error. To avoid this problem, use a qualified tbl_name.* reference

Unfortunately the why is not explained in the docs, and would likely take some digging.

Upvotes: 5

Related Questions