2

I was wondering if there was any way in Active Record to create a query with nested WHERE cases like:

SELECT * FROM Users WHERE FirstName = 'John' AND (LastName = 'Smith' OR LastName = 'Jones');

2 Answers 2

2

Yes you can use where() function

$this->db->select('*');
$this->db->from('Users ');
$this->db->where("FirstName = 'John'");
$this->db->where(" (LastName = 'Smith' OR LastName = 'Jones') ");
$result=$this->db->get();

Active Record

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

1 Comment

Thank you, that worked perfectly. I wasn't aware you could enter straight SQL like that in the where function.
0

You need to pass the WHERE clause in order to do this.

$this->db->where("FirstName = 'John' AND (LastName = 'Smith' OR LastName = 'Jones')");

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.