de-vraag
  • 質問
  • タグ
  • ユーザー
通知:
報酬:
登録
登録すると、質問に対する返答やコメントが通知されます。
ログイン
すでにアカウントをお持ちの方は、ログインして新しい通知を確認してください。
追加された質問、回答、コメントには報酬があります。
さらに
ソース
編集
Matt Fenwick
Matt Fenwick
質問

MySQLクエリに '*'を追加すると構文エラーが発生するのはなぜですか?

なぜこれが構文エラー(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?

4 2011-10-27T20:53:38+00:00 3
Matt Fenwick
Matt Fenwick
編集された質問 3日 5月 2012 в 7:48
プログラミング
sql
mysql
select
John Flatness
27日 10月 2011 в 8:57
2011-10-27T20:57:17+00:00
さらに
ソース
編集
#56793078

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 qualified tbl_name.* reference

    SELECT 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 be by itself or a "normal" select list.

7
0
meagar
27日 10月 2011 в 8:55
2011-10-27T20:55:55+00:00
さらに
ソース
編集
#56793077

同じフィールドを2回選択している可能性があります。次のクエリ

select name, * from <...>

* には name が含まれるので、 name を明示的に指定しています。

以下は有効なので、これは説得力のある議論ではありません:

select name, name from <...>

以下も同様です

select name, users.* from users

どちらも同じフィールドを複数回選択します。

おそらくMySQLの構文上の制限にすぎないでしょう。

2
0
Steve Claridge
27日 10月 2011 в 8:59
2011-10-27T20:59:38+00:00
さらに
ソース
編集
#56793079

しかし

select *, f from blegg 

うまく動作します。

おそらく、非修飾*が選択の最初の式として表示される必要がありますか?

1
0
質問の追加
カテゴリ
すべて
技術情報
文化・レクリエーション
生活・芸術
科学
プロフェッショナル
事業内容
ユーザー
すべて
新しい
人気
1
Денис Анненский
登録済み 1日前
2
365
登録済み 5日前
3
True Image
登録済み 6日前
4
archana agarwal
登録済み 1週間前
5
Maxim Zhilyaev
登録済み 1週間前
© de-vraag :年
ソース
stackoverflow.com
ライセンス cc by-sa 3.0 帰属