the table looks like this:
tag | entryID
----+---------
foo | 1
foo | 2
bar | 3
And now i want to get all tags with its usage:
foo | 2
bar | 1
How can I do this?
Thank you
The correct syntax for using COUNT(DISTINCT) is: SELECT COUNT(DISTINCT Column1) FROM Table; The distinct count will be based off the column in parenthesis. The result set should only be one row, an integer/number of the column you're counting distinct values of.
Yes, you can use COUNT() and DISTINCT together to display the count of only distinct rows. SELECT COUNT(DISTINCT yourColumnName) AS anyVariableName FROM yourTableName; To understand the above syntax, let us create a table.
To count the number of different values that are stored in a given column, you simply need to designate the column you pass in to the COUNT function as DISTINCT . When given a column, COUNT returns the number of values in that column. Combining this with DISTINCT returns only the number of unique (and non-NULL) values.
Count would show a result of all records while count distinct will result in showing only distinct count. For instance, a table has 5 records as a,a,b,b,c then Count is 5 while Count distinct is 3.
select tag, count(*)
from MyTable
group by tag
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With