I am looking for join query. Actually I have main three table.
- Category [cat_id(PK), cat_name]
- Product [pro_id(PK), cat_id(FK),pro_name]
- Company [com_id(PK), cat_id(FK),pro_id(FK),...]
Now I have list of Category in list view. So when user click delete selected category should be delete.
Now I can check for single table Whether same cat_id
is used by other two tables or not ?
if(check cat_id is used in other tables or not)
{
alert("you can't delete because category is used by some other table(s).");
}
else
{
alert("record deleted.");
}
Now i can check same thing from single table using NOT IN
like,
DELETE FROM CATEGORY WHERE cat_id NOT IN (SELECT DISTINCT cat_id FROM PRODUCT);
This will only delete selected cat_id if it is not available in PRODUCT table.
Even i have try with JOIN QUERY
also as below,
SELECT CATEGORY.cat_id FROM CATEGORY INNER JOIN PRODUCT ON CATEGORY.cat_id = PRODUCT.cat_id;
But i don't have idea how to use third table.So, I am wondering how can i check for multiple table.
Please help to solve this query.