I have a main table called arrests
with primary key arrest_key
that is currently empty. I have a staging table called arrests_temp
that contains one month of data. The staging table looks like this: https://i.imgur.com/v8QGynD.png
I have the following so far:
UPDATE arrests
SET arrests.arrest_key = arrests_temp.arrest_key
FROM arrests LEFT JOIN arrests_temp
ON arrests.arrest_key = arrests_temp.arrest_key
WHERE arrests.arrest_key != arrests_temp.arrest_key;
INSERT INTO arrests (arrest_key, arrest_date, pd_cd, pd_desc, ky_cd)
SELECT arrest_key, arrest_date, pd_cd, pd_desc, ky_cd
FROM arrests_temp
WHERE arrest_key NOT IN (SELECT arrest_key FROM arrests);
I keep getting the following error:
ProgrammingError: (pymysql.err.ProgrammingError) (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 arrests LEFT JOIN arrests_temp \n ON arrests.arrest_key = arrests_temp.ar' at line 3")
[SQL:
UPDATE arrests
SET arrests.arrest_key = arrests_temp.arrest_key
FROM arrests LEFT JOIN arrests_temp
ON arrests.arrest_key = arrests_temp.arrest_key
WHERE arrests.arrest_key != arrests_temp.arrest_key;
]
(Background on this error at: http://sqlalche.me/e/13/f405)
What am I doing wrong?
You were using the SQL Server syntax but MySQL works differently
UPDATE arrests
LEFT JOIN arrests_temp ON arrests.arrest_key = arrests_temp.arrest_key
SET arrests.arrest_key = arrests_temp.arrest_key
WHERE arrests.arrest_key != arrests_temp.arrest_key
Every DB engine has a somewhat different SQL syntax.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments