Reputation: 537
I have two table subscribers and charge
I am trying to get all subscribers list which not in charge table from previous two months.
I am new in sql don't know how can get this, I have tried below sql which not working
select * subscribers UNION select *from charge;
Table structure : subscribers :
id || mobile|| subscribers_date
charge :
id || mobile || status || charge_date
my date field name is subscribers_date.
Upvotes: 0
Views: 40
Reputation: 4402
Use the NOT IN operator.
Select * from subscribers where
mobile not in (select mobile from charge where charge_date > '2 months ago')
And your charge
table needs a covering index on charge_date, mobile
Upvotes: 1