这个sql查询在哪里包含语法错误?

时间:2011-10-27 16:12:45

标签: mysql

无法理解这里语法错误在哪里?

INSERT INTO `playlist_playlistentry` VALUES (playlist_id, media_id, order_by, added)
SELECT (699086, `playlist_playlistentry`.`media_id`, `playlist_playlistentry`.`order` order_by, `playlist_playlistentry`.`added`)
FROM `playlist_playlistentry`
WHERE `playlist_playlistentry`.`playlist_id` = 371390

工作台中的错误如下所示:

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 'SELECT 699086, `playlist_playlistentry`.`media_id`, `playlist_playlistentry`.`or' at line 2

4 个答案:

答案 0 :(得分:4)

删除VALUES关键字。从select语句插入时不使用它。

INSERT INTO `playlist_playlistentry` 
    (playlist_id, media_id, order_by, added)
    SELECT 699086, `playlist_playlistentry`.`media_id`, `playlist_playlistentry`.`order` order_by, `playlist_playlistentry`.`added`
        FROM `playlist_playlistentry`
        WHERE `playlist_playlistentry`.`playlist_id` = 371390

答案 1 :(得分:1)

删除VALUES

INSERT INTO `playlist_playlistentry` (playlist_id, ...) 

同时从SELECT part

中删除括号
SELECT (699086, ... )

成:

SELECT 699086, ... 

答案 2 :(得分:1)

您使用的是一个背景字符而不是一个撇号'吗?看起来您在SELECT列列表周围有无关的问题。

答案 3 :(得分:1)

您正在使用select来获取值,但是从您的查询中我想要放置列列表。正确的语法是:

INSERT INTO `playlist_playlistentry`(playlist_id, media_id, order_by, added)
SELECT 699086, `playlist_playlistentry`.`media_id`, `playlist_playlistentry`.`order` order_by, `playlist_playlistentry`.`added`
FROM `playlist_playlistentry`
WHERE `playlist_playlistentry`.`playlist_id` = 371390