I have a MySQL database similar to:
+----+---------+---------+------------------+....
| id | unique1 | unique2 | genaric_data |....
+----+---------+---------+------------------+....
| 0 | 100 | 1C7 | {data container} |....
+----+---------+---------+------------------+....
| 1 | 100 | 1C7 | {data container} |....
+----+---------+---------+------------------+....
| 2 | 100 | 1C8 | {data container} |....
+----+---------+---------+------------------+....
| 3 | 101 | --- | {data container} |....
+----+---------+---------+------------------+....
| 4 | 102 | 0 | {data container} |....
+----+---------+---------+------------------+....
| 5 | 103 | 1 | {data container} |....
.................................................
I need a way to add an extra column that gives the number of times all unique fields are used. I will then need to clean up the data manually.
I want a query to return:
+----+---------+---------+------+------------------+....
| id | unique1 | unique2 | dupe | genaric_data |....
+----+---------+---------+------+------------------+....
| 0 | 100 | 1C7 | 2 | {data container} |....
+----+---------+---------+------+------------------+....
| 1 | 100 | 1C7 | 2 | {data container} |....
+----+---------+---------+------+------------------+....
| 2 | 100 | 1C8 | 1 | {data container} |....
+----+---------+---------+------+------------------+....
| 3 | 101 | --- | 1 | {data container} |....
+----+---------+---------+------+------------------+....
| 4 | 102 | 0 | 1 | {data container} |....
+----+---------+---------+------+------------------+....
| 5 | 103 | 1 | 1 | {data container} |....
.......................................................
This has been a problem I have had for a while and currently my only solution is to export the data to excel and use it to find the duplicates.
Thanks.
Edit: The possible duplicate is not a solution to my problem since when I execute:
SELECT *,count(*) FROM `database`
GROUP BY `unique1`
HAVING count(*) > 1
On PhpMyAdmin(All I'm allowed access to) it merges anything with the same unique1 into one line.
GROUP BY unique2along with aselect count(*)and thenJOINback to the table you have already.