phpmysqlcodeigniteractiverecordwhere-clause

How to convert WHERE greater than conditions to CodeIgniter's active record


This is what I want:

SELECT DISTINCT first_name,last_name 
FROM employees e 
INNER JOIN salaries s ON e.emp_no = s.emp_no 
WHERE e.birth_date > '1963-01-01' 
AND s.salary>150000

I've tried this and I get the names I want but also an additional 12 names. Something is wrong.

$this->db->distinct();
$this->db->select('first_name, last_name');
$this->db->from('employees');
$this->db->join('salaries s', 'e.emp_no = s.emp_no', 'inner');
$this->db->where('e.birth_date > 1963-01-01');
$this->db->where('s.salary > 150000');

$result = $this->db->get();

Solution

  • In the where clause, the operator should be entered in the first parameter to be compared with the second parameter, the values.

    $this->db->where('e.birth_date >', 1963-01-01);
    $this->db->where('s.salary >', 150000');