Welcome Guest, Not a member yet? Register   Sign In
SQL query with 1 fixed and 2 OR conditions
#2

You need to use Query Grouping. See https://www.codeigniter.com/user_guide/d...html#group

Code:
<?php

$builder->select('*')->from('my_table')
    ->groupStart()
        ->where('a', 'a')
        ->orGroupStart()
            ->where('b', 'b')
            ->where('c', 'c')
        ->groupEnd()
    ->groupEnd()
    ->where('d', 'd')
    ->get();
/*
* Generates:
* SELECT * FROM (`my_table`) WHERE ( `a` = 'a' OR ( `b` = 'b' AND `c` = 'c' ) ) AND `d` = 'd'
*/
Reply


Messages In This Thread
RE: SQL query with 1 fixed and 2 OR conditions - by sclubricants - 11-21-2023, 11:58 AM



Theme © iAndrew 2016 - Forum software by © MyBB