Reputation: 13
I have 2 MySQL table.
id | sellDate
1 | 2011-05-30
2 | 2011-09-15
3 | 2016-03-04
4 | 2017-05-06
5 | 2018-04-16
id | activation | program_id
1 | 2011-05-30 | 1
2 | 2011-09-15 | 2
3 | 2016-03-04 | 3
4 | 2017-05-06 | 4
The programs
table contains when a customer buy a program, the activation
contains when the customer activated it. I want to print that customers where the customer buy the program where the id is 5, but not activate it, so the program id 5 isn't in the activation table. How can I solve this?
Upvotes: 1
Views: 40
Reputation: 954
SELECT id FROM programs WHERE id NOT IN (SELECT program_id FROM activation);
If you use DBMS that has better JOIN performance:
SELECT id FROM programs p LEFT OUTER JOIN activation a ON p.id=a.program_id WHERE a.program_id IS NULL;
Upvotes: 2
Reputation: 9898
SELECT id FROM programs WHERE id NOT IN (SELECT program_id FROM activation);
Upvotes: 0