I have the following table with these records as example:
+------+---------+---------+ | key | amount1 | amount2 | |------|---------|---------| | A | 100 | 0 | | B | 0 | 100 | | C | 100 | 0 | | D | 66 | 34 | | E | 99 | 12 | | F | 100 | 12 | | G | 12 | 99 | +------+---------+---------+
I'd like to delete all the records where fields amount1 of one row = amount2 of another row, but only by pairs : If I find 2 records with amount1 = amount2 then I can delete them, if I find a third record I have to keep it.
Example : The 1st record above with key = A has amount1 = 100 and amount2 = 0, the pair here will be key B where amount1 = 0 and amount2 = 100. row with key = C must be kept.
+------+---------+---------+ | key | amount1 | amount2 | +------+---------+---------+ | A | 100 | 0 | | B | 0 | 100 | Pair found with key = A : Delete key = A and key = B | C | 100 | 0 | No pair found as the 2 first records compose a pair | D | 66 | 34 | No pair found | E | 99 | 12 | No pair found | F | 100 | 12 | No pair found | G | 12 | 99 | Pair found with key = E : Delete records with key = E and key = G +------+---------+---------+
The expected result is the below one :
+------+---------+---------+ | key | amount1 | amount2 | +------+---------+---------+ | C | 100 | 0 | | D | 66 | 34 | | F | 100 | 12 | +------+---------+---------+
So either I would like to determine all the pairs then delete them, or display directly only the rows with no pair.
Any clue ?
Thanks in advance for your help,