Hey, I want to update popularity(int) field in every email_data row, and set it equal to some formula of how many votes it has, how old it is, etc.
This is what I have so far:
Code:
UPDATE email_data SET popularity =
(SELECT (SUM(up) - SUM(down)*2)
FROM rating WHERE email_data_id=email_data.id)
+
(SELECT -DATEDIFF(CURDATE(), email_data.timestamp))
But this only works on a few rows, because if the email_data was never "rated" it won't have a row in the 'rating' table and will be skipped, I'd like it to just have a value of 0 in that case. Can anyone help me out on how to set up this query?