なぜこれが構文エラー(MySQL 5)を引き起こすのですか?
mysql> select f, blegg.* from blegg limit 1;
+------+------+------+------+
| f | f | g | h |
+------+------+------+------+
| 17 | 17 | 2 | 17 |
+------+------+------+------+
1 row in set (0.00 sec)
mysql> 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
fail where select
.* ... and
select * ...
and select *,
succeed?
MySQLのマニュアルでは、 SELECT
構文:
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 ...
tbl_name.*
can be used as a qualified shorthand to select all columns from the named table:SELECT t1.*, t2.* FROM t1 INNER JOIN t2 ...
Use of an unqualified
*
with other items in the select list may produce a parse error. To avoid this problem, use a qualifiedtbl_name.*
referenceSELECT AVG(score), t1.* FROM t1 ...
ドキュメントは、 *
だけが選択リストの唯一の特殊な場合にのみ有効であることを示しているようです。ただし、解析エラーを生成する可能性があります以外の項目では、修飾されていない *
MySQL以外にも、 SQL-92標準(古いものですが、リンク可能な)
7.9
Format ::= SELECT [ ] <select list> <select list> ::=
| <select sublist> [ { <select sublist> }... ] <select sublist> ::= | ::= [ ] ::= [ AS ]
<select list>
can either beby itself or a "normal" select list.
カテゴリ技術情報文化・レクリエーション生活・芸術科学プロフェッショナル事業内容