Welcome Guest, Not a member yet? Register   Sign In
How can I query this in CodeIgniter?
#1

[eluser]ethio[/eluser]
The code below is what I want and in phpmyadmin it gives me three names which is right

Code:
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.

Code:
$this->db->distinct();
    $this->db->select('first_name, last_name');
    $this->db->from('employees e');
    $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();
#2

[eluser]Otemu[/eluser]
Try changing your where clause as follows

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

[eluser]ethio[/eluser]
thanks!
#4

[eluser]TheFuzzy0ne[/eluser]
You may come across times when you want to use database aggregate functions in a WHERE clause, or some other kind of condition, or sub-query. $this->db->where() accepts FALSE as a third parameter which will prevent it from trying to escape the string.
Code:
$this->db->where('MATCH (`field`) AGAINST ("value")', NULL, FALSE);




Theme © iAndrew 2016 - Forum software by © MyBB