I’m looking at some sql code with the following structure:
set @var =
(
select count(1) from
(
select * from table where field = 1
)
someVariable
)
It won’t seem to run unless “someVariable” is in the statement. My question is, what does this “someVariable” represent, and why is it in the query? I don’t understand why I can’t set @var to the select count statement outright, so the “someVariable” is really throwing me off.
Derived tables need to have aliases.
someVariableis functioning as an alias in this case.