Welcome Guest, Not a member yet? Register   Sign In
SQL Question
#1

[eluser]mrwilson1[/eluser]
I have a query I am trying to write but not getting data back from it.

The query is :
Code:
SELECT DISTINCT `visitor_agent`, COUNT(`visitor_agent`)AS count FROM `visitor` group by `visitor_agent` order by count desc";

I am writing it out as

Code:
function browsers(){
    $this->db->distinct('visitor_agent');
    $this->db->select('COUNT(visitor_agent)AS count');
    $this->db->group_by('visitor_agent');
    $this->db->order_by('count', 'desc');
    $query = $this->db->get('visitor');
    return $query->result();        
    }

I am getting about half the numerals from the count cloumm that I expect, and none of the distinct visitor_agent.

Does this query look right? Thanks
#2

[eluser]theprodigy[/eluser]
Quote:
Code:
SELECT DISTINCT `visitor_agent`, COUNT(`visitor_agent`)AS count FROM `visitor` group by `visitor_agent` order by count desc";

Try:
Code:
SELECT `visitor_agent`, COUNT(`visitor_agent`)AS count FROM `visitor` group by `visitor_agent` order by count desc";

(remove the distinct)
Grouping by visitor_agent is going to have it only show one anyway, no need for the distinct
#3

[eluser]mrwilson1[/eluser]
Thanks. Worked like a charm!




Theme © iAndrew 2016 - Forum software by © MyBB