Hi @Artimes ,
Yes, for the same problem, many times TSQL can have multiple methods.
First I want to explain that TableA is not an intermediate table, it is not even a real table. It is a subquery in the form of a table, that is, a subquery is used instead of a table where it should be. This is called a table expression. The main function of table expressions is to construct various temporary data sets conveniently.
TableA in your code is a common table expression, which is defined with with. After TableA is defined, it can be referenced in any code afterwards.
If you do not want to use a common table expression, you can choose to use a derived table (another table expression) instead, please refer to:
SELECT B.*,t.Col1,t.Col2
FROM B
LEFT JOIN (SELECT *,'hello' AS Col1, 1 AS Col2 FROM A) t
ON t.Id = B.Id
If you have any question, please feel free to let me know.
Regards
Echo
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.