I have columnA in MySQL. I'm trying to write a SELECT that returns columns uid and count. Column uid represents the unique values from columnA. Column count represents the number of times the unique uid was found in columnA.
This returns column uid. I'm having a difficult time figuring out what to do next.
SELECT DISTINCT uidUser FROM appRegistrations as uid
Any help is greatly appreciated.
columnA
| UID |
*********
| 101 |
---------
| 102 |
---------
| 101 |
---------
| 103 |
---------
| 102 |
---------
| 101 |
SELECT OUTPUT
| uid | | count |
********** *********
| 101 | | 3 |
---------- ----------
| 102 | | 2 |
---------- ----------
| 103 | | 1 |
---------- ----------
Solution I assumed I needed DISTINCT values first, then find a way to count. I was wrong. I used Select distinct values, and count number of occurrences to solve my problem.
SELECT
UID,
count(UID) as count
FROM tableName
GROUP BY UID