turtle
turtle

Reputation: 8073

SQLite query aggregation

I have two columns of data in a SQLite table: users and URL. I'm trying to construct a query that returns the users with a particular URL. I'm trying the following:

SELECT url, COUNT(url) as RESULT 
FROM bookmarks 
GROUP BY url 
order by RESULT desc
limit 10;

This query is close, but I only get back one user—not an aggregation of all the users for a given bookmark URL.

Upvotes: 1

Views: 68

Answers (2)

Piruz Hashemian
Piruz Hashemian

Reputation: 168

Yes and for more details:

SELECT ... GROUP_CONCAT(users ORDER BY users ASC SEPARATOR ', ') AS user_list
FROM ...

Upvotes: 1

juergen d
juergen d

Reputation: 204746

Use group_concat() to get a list of users for every url

SELECT url, 
       COUNT(users) as RESULT, 
       group_concat(users) as user_list
FROM bookmarks 
GROUP BY url 
order by RESULT desc 
limit 10;

Upvotes: 2

Related Questions