Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why must the asterisk come first?

Tags:

syntax

mysql

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.
like image 808
mpen Avatar asked Feb 21 '26 14:02

mpen


1 Answers

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.

like image 58
sjagr Avatar answered Feb 24 '26 04:02

sjagr



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!