create table
#tempTable (
col1 int,
col2 int,
col3 int
)
insert into
#tempTable (
col1,
col2,
col3
)
select
col1,
col2,
col3
from
Table3
inner join Table2
on Table1.col1 = Table2.col2
where col1 = 5
select
col2,
case when col1 = 3
then 'something'
else 'somethingelse'
end
from #tempTable
where
col1 = 5
and (
col2 = 5
or col3 in (
select field
from Table2
where
somecol = 2
and othercol = 5
)
)