Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (20.3k points)

Why doesn't the following work?

SELECT name FROM (SELECT name FROM agentinformation)

I guess my understanding of SQL is wrong because I would have thought this would return the same thing as

SELECT name FROM agentinformation

Doesn't the inner select statement create a result set which the outer SELECT statement then queries?

1 Answer

0 votes
by (40.7k points)

You should use the alias in the subquery like this:

SELECT ID FROM (SELECT ID FROM agent_information) s  

Or

More explicitly you can use this way:

SELECT s.ID FROM (SELECT ID FROM agent_information) s  

Browse Categories

...