I am a beginner in SQL and trying to solve an issue.
I have two tables on my database, company and invoice as below
Company table
id name active
1 company A True
2 company B True
3 company C True
4 company D True
5 company E True
Invoice table
id date companyid
1 18/01/2018 4
2 06/05/2014 1
3 04/03/2017 4
4 25/05/2016 3
5 17/04/2018 2
6 10/11/2017 3
I want to get a get a list of unique values of companies and change the "active" column value to False if a company doesn't have any invoice after 01/01/2017. By saying this, Company A and E active column should be changed to False. The desired outcome would be this:
id name active
1 company A False
2 company B True
3 company C True
4 company D True
5 company E False
I have tried this but this is just half and I could't sort out the rest of the solution:
select distinct A.* from company A
inner join invoice B
on B.companyid = A.id
where B.date < '20170101'