Table Reference in FROM and Subqueries

In my main SELECT statement, the FROM clause has the following

#1

FROM
	[SampleIQ_App].[CalculationSource] AS MnTbl LEFT JOIN
	[SampleIQ_App].[Calculations] AS Tbl2 ON Tbl2.CalculationID = MnTbl.CalculationID

In my SubQueries, I have:
#2

FROM [SampleIQ_App].[Calculations] AS Tbl2

My question is...do I need to redefine Tbl2 in every Subquery, can I just refer to Tbl2 referencing the one declared in the #1 portion?

Thank you.

As long as it's enclosed in the subquery then the aliases won't conflict:

DROP TABLE IF EXISTS #a, #b;
CREATE TABLE #a(i int);CREATE TABLE #b(j int);
INSERT #a VALUES(1),(2);INSERT #b VALUES(2),(3);

SELECT *, (SELECT TOP 1 I FROM #b TBL1 ORDER BY TBL1.j) subquery_column
FROM #a TBL1 
LEFT JOIN #b TBL2 ON TBL1.i=TBL2.j

However, from a management standpoint, if you can make your aliases unique you'll have a better time working with larger queries. This also applies to common table expressions (CTEs) and subqueries in the FROM clause.

Edit: upon re-reading your post I'm not sure I answered your question, so if I didn't please clarify.

Edit 2: And I have a typo in my example that possibly undermines my assertion. Let me know if you spot it. :slight_smile: