サブクエリで取得した結果を、別のテーブルに挿入するときにハマったこと。
Qiitaに投稿するには稚拙すぎるかもと思いましたが、自分のためにも投稿して記録しておきます・・・。
ハマったこと
weathers テーブルの weather カラムに、 days テーブルから取得した weather カラムを挿入する。
正しいクエリ文
insert into weathers (weather) select distinct weather from days;
間違ったクエリ文
insert into weathers (weather) values (select distinct weather from days);
エラーメッセージ
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
'select distinct weather from days)' at line 1
まとめ
サブクエリで取得した結果をつっこむSQL文には、__Values__はいらない。