How do I avoid a repetitive subquery JOIN in SQL?
Posted
by Karl
on Stack Overflow
See other posts from Stack Overflow
or by Karl
Published on 2010-03-25T13:44:38Z
Indexed on
2010/03/25
14:03 UTC
Read the original article
Hit count: 640
Hi
In SQL Server 2008:
I have one table, and I want to do something along the following lines:
SELECT T1.stuff, T2.morestuff from
(
SELECT code, date1, date2 from Table
) as T1
INNER JOIN
(
SELECT code, date1, date2 from Table
) as T2
ON T1.code = T2.code and T1.date1 = T2.date2
The two subqueries are exactly identical. Is there any way I can do this without repeating the subquery script?
Thanks
Karl
© Stack Overflow or respective owner