I'm trying to fetch records from table
PaymentToken if its
AccountNumber matched but
select DISTINCT DTR_PT.Id, DTR_PT.AccountNumber, DTR_PT.CardNumber, DTR_PT.ExpirationDate, DTR_PT.CardHolderName, DTR_PT.AccountToken, DTR_PT.CreatedDate, DTR_PT.Active from Dev_NeoGateway_DTR.dbo.PaymentToken as DTR_PT JOIN Dev_NeoGateway_DTA.dbo.DTA_Customer as DTA_C on DTA_C.Id = DTR_PT.AccountNumber WHERE DTR_PT.AccountToken NOT IN (select DTA_PI.CardToken FROM Dev_NeoGateway_DTA.dbo.DTA_PaymentInstrument as DTA_PI )
Because of the
WHERE clause, this query takes a lot of time as it queries all the table again and again.