Satu Sultana
Satu Sultana

Reputation: 537

Compare two table data and get list uncommon data

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

Answers (1)

Cine
Cine

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

Related Questions