The following is an example structure:
table `pligg`
#id #alpha #num
1 a null
2 b null
3 c null
4 a null
5 d null
6 b null
7 a null
8 e null
I’d like to update the databse like this after a single mysqli query:
table `pligg`
#id #alpha #num
1 a 1
2 b 1
3 c 1
4 a 2
5 d 1
6 b 2
7 a 3
8 e 1
What I’m trying to do is to update the column num with the number of duplicate.
I tried this query, but in vain
UPDATE pligg SET 'num' = COUNT(DISTINCT alpha) WHERE 'id'<id
This should do the trick:
SQLFiddle Demo