views:

33

answers:

4

Hi

I am using the following mysql query for grouping referrersource.

SELECT referrersource,count(referrersource) as counts 
FROM request_events  
where referrersource!='' 
AND landingpage_collectionid=1 
group by referrersource

Here, I would like to order by my resultset in ascending order.How can I alter my above query.Any suggections please

A: 

Add an ORDER BY clause.

SELECT  referrersource
        ,count(referrersource) as counts 
FROM    request_events 
where   referrersource!='' 
        AND landingpage_collectionid=1 
group by 
        referrersource
order by
        2        
Lieven
+1  A: 

Adding ORDER BY counts DESC ?

pharalia
A: 
 SELECT referrersource,count(referrersource) as counts 
 FROM request_events  
 where referrersource!='' 
 AND landingpage_collectionid=1 
 group by referrersource
 ORDER BY 2
Michael Pakhantsov
A: 

Just add an ORDER BY clause, eg.

ORDER BY count(referrersource)
ar