Question : SQL Query Taking a long time to run/load

Hi,
ive got a query, that was written from another quetion:
http://www.experts-exchange.com/Programming/Languages/SQL_Syntax/Q_26369151.html#a33329217

this works fine on the sample data, however not when i scalre the tables up into the 300,000+ range
the query just takes for ever to run (ive not seen it finish yet!)

This is the query.
If you take out the last line, its fine but has dups in it, if you add the last line, it all slows down

select t1.UserID, t1.ManagerID, t1.SomeData,t1.SomeYear as Year1, NZ(t2.SomeYear, "-") as Year2
from MasterTable t1
left join SecondTable t2
on t2.UID = t1.userid
UNION
select UID, ManagerID, SomeData,"-" as Year1, SomeYear as Year2
from SecondTable
WHERE UID NOT IN (SELECT userid FROM MasterTable)

Answer : SQL Query Taking a long time to run/load

Try this for speed
1:
2:
3:
4:
5:
6:
7:
8:
9:
select t1.UserID, t1.ManagerID, t1.SomeData,t1.SomeYear as Year1, NZ(t2.SomeYear, "-") as Year2
from MasterTable t1
left join SecondTable t2
on t2.UID = t1.userid
UNION 
select st.UID, st.ManagerID, st.SomeData,"-" as Year1, st.SomeYear as Year2
from SecondTable st
left join mastertable m
on m.userid = st.uid where (m.userid is null)
Random Solutions  
 
programming4us programming4us