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

[eluser]Tim Brownlaw[/eluser]
I just tried something similar and got this...

You can add in extra Select Statements and for your count - it's best to use a primary index if you have one, Try to avoid using * and be specific.

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


Also you can loose the "From" statement and put the table name in the get
Code:
function get_residency()
{
        $this->db->select('residency');
        $this->db->distinct();
        $this->db->select('count(id) as count');      // New Bit
        $this->db->where('active', '1');
        $this->db->group_by('residency);
        $query = $this->db->get('users');             // Changed
        return $query->result();
}

Those are just some of the ways you can achieve what you want.


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