发现很难进行sql查询

vjrehmav  于 2021-06-18  发布在  Mysql
关注(0)|答案(2)|浏览(300)

我检查了$posts\u not \u to \u select as simple array中的数据,其他一切都很好,但显示的错误如下所示:
异常#0(zend#u dbŠu statementŠexception):sqlstate[42000]:语法错误或访问冲突:1064您的sql语法有错误;请查看与mysql服务器版本对应的手册,以了解在“where”附近使用的正确语法 entity_id 不在(从mst\u blog\u store\u post where not stor'第1行选择post\u id,查询为:select*from mst_blog_post_entity 订货人 created_at 描述限制1,其中 entity_id 不在(从mst\u blog\u store\u post中选择post\u id,其中not store\u id=1)

$posts_not_to_selectssql1 = "SELECT post_id FROM mst_blog_store_post WHERE NOT store_id = $storeID";
    $posts_not_to_select12 = $connection->fetchAll($posts_not_to_selectssql1);
    $posts_not_to_select = array();

    foreach ($posts_not_to_select12 as $key => $value){
        $posts_not_to_select[$key] = $value['post_id'];
    }

    "SELECT * FROM `mst_blog_post_entity` ORDER BY `created_at` ASC LIMIT 1 WHERE `entity_id` NOT IN ( '" . implode( "', '" , $posts_not_to_select ) . "' )"
au9on6nz

au9on6nz1#

SELECT * FROM `mst_blog_post_entity` WHERE `entity_id` NOT IN ( '" . implode( "', '" , $posts_not_to_select ) . "' )" ORDER BY `created_at` ASC LIMIT 1;

只要在phpmyadmin的sql部分运行这个查询,一切都会正常工作。

4c8rllxm

4c8rllxm2#

ORDER BY 紧随其后 WHERE 条款。

SELECT * FROM `mst_blog_post_entity` 
WHERE `entity_id` NOT IN ( '" . implode( "', '" , $posts_not_to_select ) . "' )"  
ORDER BY `created_at` ASC LIMIT 1

完整的顺序是:
选择

加入
哪里
分组依据

订货人[限额]

相关问题