In MySQL, this code works fine:
select f, blegg.* from blegg limit 1;
+------+------+------+------+
| f | f | g | h |
+------+------+------+------+
| 17 | 17 | 2 | 17 |
+------+------+------+------+
1 row in set (0.00 sec)
So why does this code cause a syntax error?
select f, * from blegg limit 1;
-- * is unqualified
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near '*
from blegg limit 1' at line 1
I’ve looked through the manual but didn’t really find anything. Why does select <field>, * ... fail where select <field>, <table>.* ... and select * ... and select *, <field> ... succeed?
The MySQL manual lays all this out pretty clearly in the section on
SELECTsyntax:The documentation seems to indicate that
*by itself is only valid in the special case where it’s the only thing in the select list. However, it only says using an unqualified*with other items may produce a parse error.Beyond MySQL, the SQL-92 standard (old, but linkable) says as much:
<select list>can either be<asterisk>by itself or a “normal” select list.