0

对不起,如果我只是瞎了眼,但这没有任何意义,因为我总是这样写,我发现它有什么问题。此外,我使用了多个 SQL 解决方案,但语法仍然存在错误......

我的php代码在这里:

$sql1 = " SELECT table1.file_name, table2.path
                FROM table1 AS t1
                LEFT JOIN table2 AS t2
                ON t1.file_name = t2.path
                WHERE t2.path IS NULL OR t1.file_name <> t2.file_name OR t1.file_name <> t2.path";

    $sql2 = "INSERT INTO table3 (file_name) VALUES(".$sql1.")";

    Shopware()->Db()->query($sql2);

我的错误信息:

SQLSTATE[42000]: Syntax error or access violation: 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 table1.file_name, table2.path FROM (the first 2 letters of table1)' at line 1 in Zend\Db\Statement\Pdo.php on line 234
4

1 回答 1

3

INSERT..SELECT语句写成:

INSERT INTO ... SELECT ... FROM ...;

不像INSERT INTO ... VALUES (SELECT ... FROM ...);. _

于 2014-07-25T09:53:15.993 回答