Please provide some sample data that produces an incorrect result.
Apr 6, 2019
5
Level 4
Query builder whereIn AND whereNotIn
Hello All,
I was hoping to get some help with the following query builder. I would like to return a random listing that exists in my 'quotes' table but does not exists in my 'orders' table.
$listing = App\Listing::whereIn('id', function ($p) {
$p->select('listing_id')->from('quotes');
}, 'AND')
->whereNotIn('id', function ($q) {
$q->select('listing_id')->from('orders');
})
->get()->random();
I've spent hours trying to get this query working... It's close but still returns listings that already exists in the orders table...
Any idea what I'm doing wrong?
Level 122
$orders = Order::pluck('listing_id');
$quotes = Quote:: pluck('listing_id');
$listing::whereIn('id',$quotes)
->whereNotIn('id',$orders)
->inRandomOrder()
->first();
1 like
Please or to participate in this conversation.