Welcome Guest, Not a member yet? Register   Sign In
How do I write this SQL statement ?
#4

[eluser]bEz[/eluser]
[quote author="whobutsb" date="1234907468"]
Code:
$this->db->select('*');
$this->db->where('abc.field1', 1);
$this->db->where('abc.field2', 2);
$this->db->where('(abc.field3 = 3 OR abc.field4 = 4)');
$query = $this->db->get('abc_table')
return $query->result();

You can either write your where statement in key/value pairs like I did with fields 1 and 2 or you can write your entire where statement right in to the $this->db->where() method. Either way works just fine.

Steve[/quote]
I think you may have missed a NESTED clause.
Code:
Select *
from `abc_table` abc
where abc.field1 = 1
    and (
        abc.field2 = 2
        and (
            abc.field = 3 or abc.field4 = 4
        )
    );


Messages In This Thread
How do I write this SQL statement ? - by El Forum - 02-16-2009, 10:41 PM
How do I write this SQL statement ? - by El Forum - 02-17-2009, 12:32 AM
How do I write this SQL statement ? - by El Forum - 02-17-2009, 09:51 AM
How do I write this SQL statement ? - by El Forum - 02-17-2009, 03:51 PM
How do I write this SQL statement ? - by El Forum - 02-17-2009, 03:55 PM
How do I write this SQL statement ? - by El Forum - 02-17-2009, 03:57 PM
How do I write this SQL statement ? - by El Forum - 02-18-2009, 03:23 AM



Theme © iAndrew 2016 - Forum software by © MyBB