Let's say I have the following query:
SELECT DISTINCT(Value1,value2,value3) From table1
and get something like
# value1 value2 value3
--------------------------------------
1. result1 result1 result2
2. result1 result2 result2
3. result5 result6 result7
How would I add an extra column that tells me how many times that unique combination of values appears, such as (last column is how many times it occurs):
# value1 value2 value3 #occurred
--------------------------------------
1. result1 result1 result2 15
2. result1 result2 result2 25
3. result5 result6 result7 35
count(*)grouping by those 3 columns.distinctis not a function. Instead,distinctalters the behavior ofselect. Think of it asselect distinct, as opposed toselect all, rather than choosing columns to select. You shouldn't put parens around it, that's some non-standard MySQL thing.DISTINCTis a keyword that applies to the entire list of expressions, it's not a function. The parens aren't necessary. Extraneous parens aren't invalid, but there's no reason to include them. Asvkpnotes, remove theDISTINCTkeyword, add aGROUP BYclause, and add aCOUNT()aggregate to the SELECT list.