I have a table for customers (containing approx 45,000 records) from which I am extracting Account No., Name and Postcode as follows :-
Select a.account_no
,a.name
,a.postcode
from customers a
I have another table which contains valid UK postcodes (approx 1.6M records).
I have been asked to find out which customer records are holding invalid postcodes.
I've tried :-
Select a.account_no
,a.name
,a.postcode
from customers a
where a.postcode not in (select b.postcode from postcode_tab b)
But this query runs and runs and runs and runs.....
I've also tried using Indexes on both tables, but the NOT IN clause by-passes the Indexes and does full table scans.
Anyone got any SQL advise on how to do this query ??
Thanks.
Select a.account_no
,a.name
,a.postcode
from customers a
I have another table which contains valid UK postcodes (approx 1.6M records).
I have been asked to find out which customer records are holding invalid postcodes.
I've tried :-
Select a.account_no
,a.name
,a.postcode
from customers a
where a.postcode not in (select b.postcode from postcode_tab b)
But this query runs and runs and runs and runs.....
I've also tried using Indexes on both tables, but the NOT IN clause by-passes the Indexes and does full table scans.
Anyone got any SQL advise on how to do this query ??
Thanks.