0

Similary with this question I need to execute the following Sql query:

SELECT COUNT(*) from table where column NOT IN (SELECT table2.id from table2 where table2.someanothercolumn >0 );

Using Eloquent's query builder, therefore I tried the following (Model Table maps into table table and Model TableTwo maps into table table2):

$enties = Table::where('id',function($q){
  $q->from('table2')->select('id')->where('someanothercolumn','>',0);
})->count();

But on the cide above how I can Place the NOT IN clause?

1 Answer 1

0

Your answer is in the following snippet of code:

$enties = Table::whereNotIn('id',function($q){
  $q->from('table2')->select('id')->where('someanothercolumn','>',0);
})->count();

In other words just use the whereNotIn.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.