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 ?
source
share