【问题标题】:laravel whereIn multiple columnslaravel whereIn 多列
【发布时间】:2019-11-06 04:58:19
【问题描述】:

我正在为这个查询寻找 laravel 方式:

select * from `table` 
where (product_id, request_id) NOT IN ((66, 10),(76,23))

可能是这样的:

$ids = =array(
    ['66', '10'],
    ['76', '23']
)
DB::table('table')->whereNotInMultiple(['product_id', 'request_id'], $ids)->get();

我如何在 laravel 中做到这一点?

【问题讨论】:

    标签: php laravel eloquent where-in


    【解决方案1】:
    DB::table('table')->whereNotIn('product_id', ['66','10'])
    ->whereNotIn('request_id', ['76', '23'])->get();
    

    【讨论】:

    • 这不是原始 SQL 所做的。如果有一行(product_id=66, request_id=1),在原SQL的结果中还是会出现,但是会用这段代码排除。
    猜你喜欢
    • 2014-05-10
    • 1970-01-01
    • 2015-08-22
    • 2017-07-30
    • 2018-07-15
    • 2021-04-18
    • 2018-09-27
    • 2017-05-30
    • 2021-02-13
    相关资源
    最近更新 更多