Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

arecuk's avatar

whereNotNull OR whereNotNull problem

Hey Guys!

I need help with following statement:

        $getSNPs = $ghcCore->table('snps')->select('*')
                                          ->where($cond,$id)
                                          ->where('status',$status)
                                          ->where(function ($query) {
                                              $query->whereNotNull('odds_ratio');
                                              })
                                          ->orwhere(function ($query) {
                                              $query->whereNotNull('beta');
                                              })
                                          ->get();

It returns wrong entries. What I need is following:

  1. where cond = 1 AND
  2. where status = statusX AND
  3. where field1 OR field2 is not empty (meaning one field must havea value)

Thanks a lot! Tomas

0 likes
3 replies
bipin's avatar
         $getSNPs = $ghcCore->table('snps')
                                      ->select('*')
                                      ->where($cond,$id)
                                      ->where('status',$status)
                                      ->where(function ($query) {
                                $query->whereNotNull('odds_ratio')
                        
                            ->orwhere('beta','!=',null);
                                          })
                                      ->get();

Try this hope it will help

arecuk's avatar

thanks!

anyway, I made it this way:

        $getSNPs = $ghcCore->table('snps')->select('*')
                                          ->where(function ($query) use ($cond,$id,$status) {
                                              $query->where($cond,$id)
                                                    ->where('status',$status)
                                                    ->whereNotNull('odds_ratio');
                                              })
                                          ->orwhere(function ($query) use ($cond,$id,$status) {
                                              $query->where($cond,$id)
                                                    ->where('status',$status)
                                                    ->whereNotNull('beta');
                                              })
                                          ->get();
bestmidever's avatar
$getSNPs = $ghcCore->table('snps')->select('*')
                                                    ->where($cond,$id)
                                                    ->where('status',$status)
                                                    ->whereRaw('odds_ratio IS NOT NULL OR beta IS NOT NULL')
                                                    ->get();

Or you can use whereRaw.

Please or to participate in this conversation.