MSSQL Select From Union

If you want to select something from union join on MSSQL using this:

SELECT id FROM
(
    (SELECT id FROM t1)
    UNION
    (SELECT id FROM t2)
)

Problem is that this construct does not work because of Incorrect syntax near ‘)’ error. Solution is simple:

SELECT id FROM
(
    (SELECT id FROM t1)
    UNION
    (SELECT id FROM t2)
) AS T

Did you like the article? Send me a comment!