質問

For some reason I get the following error when running the code below:

#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 postcodes_demographics INNER JOIN latlon1 on postcodes_demographics.postc' at line 3

I don't understand what I'm doing wrong, thanks for any suggestions!

INSERT INTO pslatlong
    SELECT postcodes_demographics.*, latlon1.*,
    FROM postcodes_demographics
    INNER JOIN latlon1
    on postcodes_demographics.postcode = latlon1.postcodens;
役に立ちましたか?

解決

You have an errant comma:

 SELECT postcodes_demographics.*, latlon1.*, <--- HERE

Remove it.

他のヒント

I would be very surprised if merely removing the comma fixes the problem. When using insert, you should get in the habit of listing all the columns explicitly:

INSERT INTO pslatlong(col1, col2, . . . )
    SELECT d.col1, l.col2, . . .
    FROM postcodes_demographics d INNER JOIN
         latlon1 ll
         on d.postcode = ll.postcodens;

You need to do this to be sure that the right column is assigned the right value, to allow auto incrementing columns to be auto-incremented, and to prevent problems based on the number of columns.

This may works:

INSERT INTO pslatlong
 SELECT postcodes_demographics.*, latlon1.*
 FROM postcodes_demographics
 INNER JOIN latlon1
 on postcodes_demographics.postcode = latlon1.postcodens;
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top