简体   繁体   中英

error 1064: Update a table with a column and a number in mysql workbench

I need to update a table with 2 values, one of them is a column of another table and the second is a number ( constant 1 ), here is my code:

insert into table (col1, col2)
select colA from table2, '1' 
 where DATA_FORMAT(table2.created_at, '%y %m %d') = DATA_FORMAT(Now(), '%y %m %d');

The error message is:

Error Code: 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 ''0', '1', '1'  where DATA_FORMAT(newsletter.created_at, '%y %m %d') = DATA_FORMA' at line 2

Try this:

insert into table (col1, col2)
select colA, '1' as ColB from table2
where DATE_FORMAT(table2.created_at, '%y %m %d') = DATE_FORMAT(Now(), '%y %m %d');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM