Select Statment
hi,
i wonder if 1 can improve query.
select distinct a.source, a.returnid,b.indicator
from apple left outer join boy b
on a.returnid=b.returnid , id = '111'
and a.returnid in (select returnid cat id ='111' , left(year,4) = '2006' , source <>'me' , dup = 'n' , flag ='y')
what trying year column cat table select statment like
select distinct a.source, a.returnid,b.indicator ,year
from apple left outer join boy b
on a.returnid=b.returnid , id = '111'
and a.returnid in (select returnid cat id ='111' , left(year,4) = '2006' , source <>'me' , dup = 'n' , flag ='y')
simam
you can join cat table based on returnid field, e.g.
select distinct a.source, a.returnid, b.indicator, c.year from apple as left outer join boy as b on a.returnid=b.returnid and id = '111' inner join cat c on and a.returnid = c.returnid where c.id ='111' and c.year like '2006%' and c.source <>'me' and c.dup = 'n' and c.flag ='y'
premature optimization root of evil in programming. (c) donald knuth
naomi nosonovsky, sr. programmer-analyst
my blog
SQL Server > Transact-SQL
Comments
Post a Comment