JOIN two tables to show already purchased items
- by Norbert
I have a table where I keep all my templates:
templates
template_id
template_name
template_price
These templates can be purchased by a registered user and then are inserted in the payments table:
payments
payment_id
template_id
user_id
Is there a way to join these two tables and get not just a list of templates that have been purchased by a certain user, but all the templates? And then figure out from there which ones have already been purchased?
I used this SELECT, but only the ones that the user bought showed up. I would like to have all the rows from templates, but empty in case the user_id doesn't match.
SELECT *
FROM templates
LEFT JOIN payments
ON templates.template_id = payments.template_id
WHERE user_id = 2
GROUP BY templates.template_id