难以从另一个表填充数据

时间:2014-05-21 09:29:47

标签: mysql

作为上面的标题,我想将表中的值插入另一个

我按照建议的答案, Need to populate one table with data from another table in same database

mysql代码转到

INSERT INTO `profitdb`(`BetID`, `PlayerID`, `PlayerWL`) SELECT `betdb`.`BetID`, `betdb`.`PlayerID`,`betdb`.`BetAmount` FROM `betdb` LEFT OUTER JOIN `profitdb` ON `betdb`.`BetID` = `profitdb`.`BetID` 

但我遇到了这个错误

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 
'SELECT `betdb`.`BetID`, `betdb`.`PlayerID`,`betdb`.`BetAmount` FROM `betdb` 
LE' at line 3

这可能是我的错?

1 个答案:

答案 0 :(得分:0)

你执行INSERT INTO TABLE A(field1,2,3) VALUES(1,2,3)然后执行SELECT,这样错误就意味着你应该INSERT ... VALUES .... **;** SELECT执行2个查询,但你真正想要的是:

INSERT INTO `profitdb`(`BetID`, `PlayerID`, `Outcome`) 
SELECT `betdb`.`BetID`, `betdb`.`PlayerID`,`betdb`.`BetAmount` FROM `betdb`

将数据从一个表复制到另一个表,阅读: http://dev.mysql.com/doc/refman/5.6/en/insert-select.html