I have four tables (in the [] columns):
users [id]
products [id]
productRatings [id,value,user,product]
comments [id,product,user]
I would like to select / and end up removing productRatings where there is no corresponding single user comment for this product. That is, if the user has a product rating but does not comment, this rating should be deleted.
I believe that I could achieve this using two queries: first
SELECT user, product FROM productRatings
and then for each line:
SELECT COUNT(*) FROM comments WHERE product=productRatings.product AND user=productRatings.user
and then something like
if $queryAbove==0 : DELETE FROM productRatings WHERE id=productRatings.id
I would like to solve this problem through JOIN and learn more by example, rather than scrolling through JOIN tutorials.
join php mysql multiple-tables
dbr
source share