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

[eluser]whobutsb[/eluser]
[quote author="CuongVM" date="1234867285"]Hi everyone,

I have this SQL statement :

Select * from `abc_table` abc
where abc.field1 = 1 and
(
abc.field2 = 2 and
(abc.field = 3 or abc.field4 = 4)
);

If don't use $this->db->query() statement, how do I write this statement (by $this->db->where...)

Thanks for helping.[/quote]

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


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