Now I have the following sql:
SELECT MAX(a), MIN(a)
FROM t1 join t2 join t3
UNION ALL
SELECT MAX(b), MIN(b)
FROM t1 join t2 join t3
UNION ALL
SELECT MAX(c), MIN(c)
FROM t1 join t2 join t3
UNION ALL
SELECT MAX(d), MIN(d)
FROM t1 join t2 join t3
While table t1, t2, t3 are all huge, join them is very slow.
How can I join them just once in this query? Alias the table or create a temp table(query scope)?
And
Thanks in advance!
In SQL Server, you can use a lateral join:
SELECT v.x
FROM t1 join
t2
on . . . join
t3
on . . . cross apply
(values (a), (b), (c), (d)) v(x);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.