程序员最近都爱上了这个网站  程序员们快来瞅瞅吧!  it98k网:it98k.com

本站消息

站长简介/公众号

  出租广告位,需要合作请联系站长

+关注
已关注

分类  

暂无分类

标签  

暂无标签

日期归档  

暂无数据

Zend Framework 2 "select where not in"

发布于2023-01-19 16:47     阅读(732)     评论(0)     点赞(0)     收藏(4)


I have this simple query where I have a $posts Array that contains IDs of certain posts. And I am selecting the files associated with these posts basically:

        ->from(
            ['DO' => 'DOCUMENT']
        )
        ->columns(
            [
                'POST_ID',
                'FILENAME'
            ]
        )
        ->where('DO.FILENAME LIKE "%'.$format.'%"')
        ->where(['DO.POST_ID' => $posts])
        ->order('DO.FILENAME DESC');

Now I want to select the files that are not related to these posts. So I need to do opposite of this:

        ->where(['DO.POST_ID' => $posts])

I cannot figure out how?


解决方案


You need to use NOT IN operation

   ->from(
            ['DO' => 'DOCUMENT']
        )
        ->columns(
            [
                'POST_ID',
                'FILENAME'
            ]
        )
        ->where('DO.FILENAME LIKE "%'.$format.'%"')
        ->where->addPredicate(new Zend\Db\Sql\Predicate\Expression('DO.POST_ID NOT IN (?)', array($posts)))
        ->order('DO.FILENAME DESC');


所属网站分类: 技术文章 > 问答

作者:黑洞官方问答小能手

链接:http://www.phpheidong.com/blog/article/476827/74421a552a86f8f9963b/

来源:php黑洞网

任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任

0 0
收藏该文
已收藏

评论内容:(最多支持255个字符)