I want to do a query that will count all the ’email’ rows in my table and return all the values based on frequency. I don’t want to group the results though, I want to show every variation of the result, here is what I have so far, as you can see it sorts by frequency but merges them by group, I’d just prefer to show them all but in order of frequency.
select email
from uploads
group by email
order by count(*) desc
SQL –
CREATE TABLE uploads
(
email varchar(200)
);
INSERT INTO uploads
(email)
VALUES
('test@email.com'),
('test@email.com'),
('test@email.com'),
('test2@email.com'),
('test2@email.com'),
('test3@email.com'),
('test4@email.com');
Here Is the result I’d like
| EMAIL |
----------------------
| test@email.com |
| test@email.com |
| test@email.com |
| test2@email.com |
| test2@email.com |
| test3@email.com |
| test4@email.com |
You can join against a subquery that returns an aggregate
COUNT()per email and order by the descending count:Effectively, this produces a result like the following, though you don’t actually include the
numcolumn in theSELECTlist: