Welcome Guest, Not a member yet? Register   Sign In
I need help with this SQL query
#1

[eluser]Unknown[/eluser]
This does what I want:

SELECT distinct residency, count(*) as count
FROM users
WHERE (active = 1)
GROUP BY residency;

I am struggling to get this into my model. So far I have:

Code:
function get_residency()
{
        $this->db->select('residency');
        $this->db->distinct();
        $this->db->from('users');
        $this->db->where('active', '1');
        $query = $this->db->get();
        return $query->result();
}


How do I put the count as count part in??



Messages In This Thread
I need help with this SQL query - by El Forum - 07-30-2014, 04:37 AM
I need help with this SQL query - by El Forum - 07-30-2014, 01:16 PM
I need help with this SQL query - by El Forum - 07-30-2014, 08:37 PM
I need help with this SQL query - by El Forum - 07-31-2014, 08:18 AM



Theme © iAndrew 2016 - Forum software by © MyBB