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');