I have the following table:
Transaction_ID int(9) NO PRI NULL auto_increment
Datetime date NO NULL
Giver_ID int(9) NO NULL
Recipient_ID int(9) NO NULL
Points int(4) NO NULL
Category_ID int(3) NO NULL
Reason text NO NULL
Apparently I’ve managed to award some of our students double points for “Behaviour Week”.
I would like a list of all the rows in this transactions table where a single user (Recipient_ID) has more than one transaction with Category_ID = 16.
Each Recipient ID should only have ONE transaction with Category_ID = 16.
For example, if I had…
54784 2012-02-01 138573 137444 100 16 You have done very well in Behaviour Week! Because...
55040 2012-02-01 138573 132629 100 16 You have done very well in Behaviour Week! Because...
That’s two separate users, which is fine.
However, if I find…
54784 2012-02-01 138573 137444 100 16 You have done very well in Behaviour Week! Because...
55040 2012-02-01 138573 137444 100 16 You have done very well in Behaviour Week! Because...
Then I’ve made a mistake and I need to delete one of those rows.
Could someone please suggest a query which will list all of these potentially incorrect transactions? I’d prefer for them just to be “SELECT” so that I can manually check rather than blindly DELETE-ing.
To find Recipients IDs which have more than 1 transaction for category 16 you can use the following:
If you want to really put your mind at rest, remove the Having clause:
You can then see the number of transactions against each recipient ID and satisfy yourself that it is really 1 for each