Hi I can write this in multiple queries but I was hoping it would be possible to combine this into one.
I have three tables:
`mail`========================= #Contains a list of messages and their owning business ID.
`businessId`,`message`,`sent`
`business`====================== #Contains a business ID and a CSV of user IDs subscribed to to receive messages from this business.
`businessId`,`name`,`userIdCsv`
`user`========================= #Contains a user ID and their email.
`userId`,`email`
My goal is to first get all messages in the `mail` table that have not been sent (sent=0). Then for each each unsent message, for each `businessId` send a message to all user's emails. In other words, for each message where `sent`=0 I am trying to get rows with `mail`.`message`,`business`.`name,`business`.`userIdCsv`. Can anyone suggest a way to actually get `user`.`email` too all in one query instead of a CSV of user IDs?
Any guidance would be appreciated!
Thanks!