I am attempting to understand how nesting works in SQL server, and have produced the following code...
SELECT(*)
FROM
(
SELECT (*)
FROM MPOG_Institutions JOIN AIMS_Patients
ON MPOG_Institutions.MPOG_Institution_ID = AIMS_Patients.MPOG_Institution_ID
) AS a
My current understanding is that the inner SELECT, FROM, and JOIN statement produces a result set that is then used in the FROM statement of the outer SELECT statement. However, when this code is run I get the following syntax error:
Msg 8156, Level 16, State 1, Line 1
The column 'MPOG_Institution_ID' was specified multiple times for 'a'.
I have read that these nested result sets need aliases, hence the "AS a", but then this error occurs. Can anyone help me understand what is going on here?
Thank you!