I am trying to run a query but at some point my logic is wrong and I am having problems finding out why its not deleting / selecting the right data.
The Question I need to ask is:
How can I delete duplicates resource_type=2  FROM user_address and keep the original resource_type=2.
I've created the following queries. The problem when I test my final query and check some of the results some of them don't have a repeated resource_type=2, this shouldnt be there. I cant find the logic problem to my query.
Can anyone spot the problem?
This Query gives me 602 results When trying to find who has duplicates. Thus I've 602 user_address that are unique aparently
SELECT MIN(id)
FROM user_address 
WHERE resource_type=2  
GROUP BY member_num 
HAVING COUNT(resource_type) > 1
If i do the following query i get 7420 results
SELECT count(*)
FROM user_address 
WHERE resource_type=2 
When I do the Select query to check what would be deleted I get 6,818 results
SELECT * FROM user_address 
    WHERE id NOT IN 
    (select * from 
        (SELECT MIN(id)
            FROM user_address 
            WHERE resource_type=2  
            GROUP BY member_num 
            HAVING COUNT(resource_type) > 1
        ) as t) AND resource_type <> 1 AND resource_type <> 3 AND resource_type <> 4 
 
     
     
    