A Little Confused About Query Syntax

I just finished the Aggregate Functions topic in the Learn SQL Course and I am a little confused about the query below. Why doesn’t the ‘COUNT’ need to be told what to count?

SELECT user,
COUNT(*)
FROM hacker_news
WHERE url LIKE ‘%watch?v=dQw4w9WgXcQ’
GROUP BY 1
ORDER BY 2 DESC;

https://www.codecademy.com/learn/learn-sql

It is counting all rows with COUNT(*)
And the records returned are filtered by the WHERE clause.

1 Like

A little more explanation:

This:

SELECT user, COUNT(*)
FROM hacker_news
WHERE url LIKE '%watch?v=dQw4w9WgXcQ'
GROUP BY user
ORDER BY COUNT(*) DESC;

results in the number of times (the COUNT(*) ) a user has posted that particular URL. You’re grouping by the user and ordering by the count of times they’ve posted that link.

Ah, that makes sense. Thanks.

1 Like