I made this select statement to find duplicated rows I want to delete. I though that I simply change SELECT TO DELETE and It'd delete rows, but it didn't.
This is select statement:
select * FROM MYCARD T1
INNER JOIN( SELECT IDCARD, YEAR, MONEY FROM MYCARD GROUP BY IDCARD, YEAR, MONEY HAVING COUNT(IDCARD) > 1 ) T2 ON
T1.IDCARD = T2.IDCARD AND T1.YEAR=T2.YEAR
AND T1.MONEY = T2.MONEY
WHERE T1.IDMONEY = 5 AND IDCARD=80
AND ID not in (select min(ID)
from MYCARD
WHERE IDMONEY=5
AND IDCARD=80
group by IDCARD, YEAR);
and I wanted to use this delete:
DELETE FROM MYCARD T1
INNER JOIN( SELECT IDCARD, YEAR, MONEY FROM MYCARD GROUP BY IDCARD, YEAR, MONEY HAVING COUNT(IDCARD) > 1 ) T2 ON
T1.IDCARD = T2.IDCARD AND T1.YEAR=T2.YEAR
AND T1.MONEY = T2.MONEY
WHERE T1.IDMONEY = 5 AND IDCARD=80
AND ID not in (select min(ID)
from MYCARD
WHERE IDMONEY=5
AND IDCARD=80
group by IDCARD, YEAR);
But it doesn't work. Any ideas?
I also tried this:
DELETE FROM MYCARD
WHERE EXISTS (select * FROM MYCARD T1
INNER JOIN( SELECT IDCARD, YEAR, MONEY FROM MYCARD GROUP BY IDCARD, YEAR, MONEY HAVING COUNT(IDCARD) > 1 ) T2 ON
T1.IDCARD = T2.IDCARD AND T1.YEAR=T2.YEAR
AND T1.MONEY = T2.MONEY
WHERE T1.IDMONEY = 5 AND IDCARD=80
AND ID not in (select min(ID)
from MYCARD
WHERE IDMONEY=5
AND IDCARD=80
group by IDCARD, YEAR))