if you are using MSSql, use CTE
;with cte1 as (
select {some columns} from {some tables} where {conditions1}
),
cte2 as (
select {some other columns} from {some tables} where {conditions2}
),
cte3 as (
select {some other columns} from {some tables} where {conditions3}
)
select {some columns from all ctes} from cte1, cte2, cte3 where {conditions}
this should run faster as there is no need to insert data into temp table.
another advantage of avoiding temp table is, using temp table sometimes has really bad impact on performances, as there is only one tempdb for entire sql server and heavily use tempdb, may block other queries. just google temp table and performance impacts, you will find a lots of article on this topic
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…