I am containing database for a shop who sells pets like dog, cat etc, for my project.
I have table name Animal , where I have details of animal name , which can be discovery in another table name ANIMAL_DISCOVERY about the type ,whether its a DOG or cat or ETC.
For each dscvr type, I have 4 or 5 category like Expensive, more Expensive, cheap,affordable. This category I am maintaining in a different table name Animal_DISCOVERY_CATEGORY.
and the last table I have is the Animal_DISCOVERY_RULES that a animal should follow as his/her behaviour.
ANIMAL - ANIMAL_NAME,ANIMAL_ID
ANIMAL_DISCOVERY - ANIMAL_DISCOVERY_GROUP, ANIMAL_DISCOVERY_ID
ANIMAL_DISCOVERY_CATEGORY - ANIMAL_DISCOVERY_CATEGORY_ID,ANIMAL_DISCOVERY_CATEGORY_TEXT
ANIMAL_DISCOVERY_RULES - ANIMAL_DISCOVERY_RULES_ID,ANIMAL_DISCOVERY_ID,ANIMAL_DISCOVERY_CATEGORY_ID,ANIMAL_DISCOVERY_RULES_TEXT
Now Here is my issues, I have a lot of data in ANIMAL_DISCOVERY_RULES. For Each Animal type and its category I have duplicates rules in ANIMAL_DISCOVERY_RULES table, which I want to delete preserving only one.
Please help me on writing a query which can perform this action.
Below is the query and result
select appl.ANIMAL_NAME,cate.ANIMAL_DISCOVERY_CATEGORY_TEXT,count(ANIMAL_DISCOVERY_RULES_TEXT) AS RULE_COUNT from ANIMAL_DISCOVERY_RULES rul INNER JOIN
ANIMAL_DISCOVERY_CATEGORY cate ON rul.ANIMAL_DISCOVERY_CATEGORY_ID=cate .ANIMAL_DISCOVERY_CATEGORY_ID INNER JOIN
ANIMAL_DISCOVERY grp ON rul.ANIMAL_DISCOVERY_ID=grp.ANIMAL_DISCOVERY_ID INNER JOIN
ANIMAL appl ON grp.ANIMAL_ID= appl.ANIMAL_ID
group by cate.ANIMAL_DISCOVERY_CATEGORY_TEXT,appl.ANIMAL_NAME
Animal Name Category Rules
A1 Dog Do not use hot water for bath
A1 Cat Do not use hot water for bath
A1 Dog Do not use hot water for bath
C1 Dog Give regular injection
C1 Parrot Do not give more then 2 chilli a day
What I want is that for animal name A1 , for the category Dog there is repeated rules. I want to delete all these types of duplicate rules for all animal name group by its category.
Hope its more clear.