Range variable range in SQL Server

Consider the following statement:

SELECT a.* 
FROM tblA a 
WHERE a.Name = @Name 

UNION 

(SELECT a.* 
 FROM tblB 
 WHERE a.Name = @Name)

Note that the range variables (aka aliases) for two different tables have the same name.

Is there any potential for conflict or ambiguity in this? If all range variables (aliases) are assigned a unique name in the instruction, for example:

SELECT a.* 
FROM tblA a 
WHERE a.Name = @Name 

UNION 

(SELECT b.* 
 FROM tblB 
 WHERE b.Name = @Name)

Experience has shown that this still works ... that the scope of each range variable (alias) does not seem to extend to UNION, but depends on unsupported behavior, or range variables (aliases) have a formally defined area related to such cases ?

+4
source share
1 answer

" ". "".

SQL, , - . SELECT UNION - SELECT. - . , , .

, SQL Server.

SQL Fiddle, MySQL, PostgreSQL SQLite. , Oracle MS SQL Server , .

+3

Source: https://habr.com/ru/post/1661323/


All Articles