Reputation: 107
SELECT
[EmpNum], [EmpEmergencyContact], [Relation], [PhType], [Phone]
FROM
(SELECT
[EmpNum], [EmpEmergencyContact], [Relation], [PhType], [Phone]
FROM [EMERGENCY_CONTACT])
A simple query where I have a SELECT
statement within FROM
clause returns an error:
Incorrect syntax near ')'
Upvotes: 3
Views: 7849
Reputation: 31249
You need to put an alias on the from statement.
So change this:
FROM [EMERGENCY_CONTACT]
)
To this:
FROM [EMERGENCY_CONTACT]
) AS tbl
Like this:
SELECT [EmpNum], [EmpEmergencyContact], [Relation], [PhType], [Phone]
FROM (
SELECT [EmpNum], [EmpEmergencyContact], [Relation], [PhType], [Phone]
FROM [EMERGENCY_CONTACT]
) AS tbl
Even safer would be to use the alias on the columns like this:
SELECT
tbl.[EmpNum],
tbl.[EmpEmergencyContact],
tbl.[Relation],
tbl.[PhType],
tbl.[Phone]
FROM (
SELECT [EmpNum], [EmpEmergencyContact], [Relation], [PhType], [Phone]
FROM [EMERGENCY_CONTACT]
) AS tbl
Upvotes: 13