in

trouble aliasing columns correctly with multiple left joins


I’m trying to do multiple left joins and don’t understand why this query only works with the specified columns commented out (sub.cust1120SEF_cnt, sub.rev_1120SEF). What am I doing wrong here? I’ve tried aliasing with every alias seen here…

SELECT * FROM
(SELECT sub.FirmId, sub.rev_agg, sub.cust1040_cnt, sub.rev_1040, 
-- sub.cust1120SEF_cnt, sub.rev_1120SEF
rev3.EFRevenue as rev_1065, rev3.TinCount as cust1065_cnt FROM
(SELECT rev1.FirmId, rev1.rev_agg, rev1.cust1040_cnt, rev1.rev_1040, 
rev2.EFRevenue as rev_1120SEF, rev2.TinCount as cust1120SEF_cnt
FROM (SELECT agg.FirmId, agg.EFRevenue as rev_agg, 
ten_forty.TinCount as cust1040_cnt, ten_forty.EFRevenue as rev_1040
FROM rptsql.dbo.Prep2016_AggregatedEF agg -- 9,275
LEFT JOIN rptsql.dbo.Prep2016_1040EF ten_forty -- 8,372
ON ten_forty.FirmId = agg.FirmId WHERE agg.EFRevenue > 0) rev1
LEFT JOIN rptsql.dbo.Prep2016_1120SEF rev2
ON rev1.FirmId = rev2.FirmId) sub
LEFT JOIN rptsql.dbo.Prep2016_1065EF rev3 -- 1,415
ON sub.FirmId = rev3.FirmId) sub1
LEFT JOIN dbo.Prep2016_1120EF rev4
ON sub1.FirmId = rev4.FirmId



Source: https://stackoverflow.com/questions/70602699/trouble-aliasing-columns-correctly-with-multiple-left-joins

wip-image-zoom on angularJS

Vodafone Idea Has Paid LF, SUC Dues for Q2 FY22