2016-07-12 10 views
0

私は非常に新しいMySQLですが、このロードブロッキングを打つまでは成功しました。どんな助けでも大歓迎です。#1064 - SQL構文にエラーがあります。近くにFROM

表2の一致する列に基づいて表1を更新しようとしています。MySQLバージョンは5.5です。 - ドメイン

+--------+------------------------------------------+----------------+-----------+ 
| ID  | DomainKeyword       | GoogleSearches | GoogleCPC | 
+--------+------------------------------------------+----------------+-----------+ 
| 406499 | 1k commandments       |   NULL |  NULL | 
| 406500 | 1k feet deep        |   NULL |  NULL | 
| 406501 | 1 market square       |   NULL |  NULL | 
| 406502 | 1marketst 3012       |   NULL |  NULL | 
| 406503 | 1 massive cashflow      |   NULL |  NULL | 
| 406504 | 1 min tv         |   NULL |  NULL | 
| 406505 | 1 minutes tv        |   NULL |  NULL | 
| 406506 | 1 minutes tv        |   NULL |  NULL | 
| 406507 | 1 money mentor       |   NULL |  NULL | 
| 406508 | 1 my bia2 music       |   NULL |  NULL | 
| 406509 | 1n4j8         |   NULL |  NULL | 

表2 - googlesearches

+------+----------------------------------+----------+-------+ 
| ID | Keyword       | Searches | CPC | 
+------+----------------------------------+----------+-------+ 
| 3330 | audio buss      |  480 | 0.00 | 
| 3331 | balls to poverty     |  30 | 0.00 | 
| 3332 | boa homes      |  10 | 0.00 | 
| 3333 | bath construction    |  10 | 0.00 | 
| 3334 | bread crumbs catering   |  10 | 0.00 | 
| 3335 | complete recruit     |  90 | 0.00 | 
| 3336 | all about carpets    |  10 | 0.00 | 
| 3337 | consulting world     |  10 | 0.00 | 
| 3338 | car insurance loans    |  50 | 3.64 | 
| 3339 | building experts     |  50 | 0.00 | 
| 3340 | boyfriend jealousy    |  30 | 0.00 | 
| 3341 | avid farm shop     |  30 | 0.00 | 
| 3342 | chic bridesmaid     |  10 | 0.00 | 
| 3343 | ad wholesale      |  10 | 0.00 | 
| 3344 | buy game card     |  10 | 0.00 | 
| 3345 | daily driving     |  10 | 0.00 | 
| 3346 | church farm cottage    |  260 | 1.18 | 

表1:ここで2つのテーブルは、(同様のテーブル/列名の謝罪は、予め列命名を計画しているはず)です

ここにコマンドがありますが、私は 'FROM'が同じエラーをスローする特定のコマンドのようです:

UPDATE dest 
    SET GoogleSearches = src.Searches, 
    GoogleCPC = src.CPC 
FROM domains AS dest 
INNER JOIN googlesearches AS src 
ON dest.DomainKeyword = src.Keyword; 

コマンドを実行しようとしたとき、私は取得していますエラー:

#1064 - 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 domains AS dest INNER JOIN googlesearches AS src ON dest.DomainKeyword = ' at line 4 
+0

をお試しください'UPDATE domains、googlesearches SET GoogleSearches = src.Searches、GoogleCPC = src.CPC domains.DomainKeyword = googlesearches.Keyword;'。私はこれを動かすと答えに移ります。 –

+0

ジョイントパターンで更新すると、末尾に「SET」が来る – Drew

+1

[MYSQLのUpdateステートメントで内部結合を使用する方法]の複製が可能です。(http://stackoverflow.com/questions/8057565/how-to-use- update-statement-in-mysql) – Drew

答えて

0

を試してみてくださいこの:...私はそれは、SQL ServerよりもMySQLでの逆転だと思うあなたのクエリを逆 :

UPDATE domains AS dest 
INNER JOIN googlesearches AS src ON dest.DomainKeyword = src.Keyword 
    SET dest.GoogleSearches = src.Searches, 
    dest.GoogleCPC = src.CPC; 
+0

パーフェクト、最初の投稿は2分で解決されたstackoverflowに投稿しました! :) – Hungry

0

私は間違っていないよ場合は、複数のテーブルを持つMySQLの `UPDATE`のクエリはようになります。この

UPDATE domains dos, googlesearches gs SET dos.GoogleSearches = gs.Searches WHERE dos.DomainKeyword = gs.Keyword; 
関連する問題