I have a db with some tables like this:
- fruitsTable
id name numberOfPeople
1 apple 3
2 orange 4
3 cherry 1
- peopleTable
person fruit
john apple
john orange
john cherry
jack apple
jack orange
ryan apple
ryan orange
meg orange
Think that peopleTable get changed everyday and consists of tens of thousands of rows. Also, the fruitsTable has more than thousand rows.
How can I calculate the numberOfPeople column, periodically?
I am planning to set up a daily cron job which will trigger a SQL command in order to calculate the number.
Assuming that I have no experience with those JOIN commands in SQL, What kind of SQL command do I need to use without having any performance issue?
numberOfPeoplecolumn and I also need to update it frequently as thepeopleTablechanges.