T-SQL - What is an inline-view?

2019-02-14 10:47发布

问题:

I recently answered this question how-to-call-user-defined-function-in-order-to-use-with-select-group-by-order-by

My answer was to use an inline view to perform the function and then group on that.

In comments the asker has not understood my response and has asked for some sites / references to help explain it.

I've done a quick google and haven't found any great resources that explain in detail what an inline view is and where they are useful.

Does anyone have anything that can help to explain what an inline view is?

回答1:

From here: An inline view is a SELECT statement in the FROM-clause of another SELECT statement. In-line views are commonly used simplify complex queries by removing join operations and condensing several separate queries into a single query.



回答2:

I think another term (possibly a SQL Server term) is 'derived table'

For instance, this article:

http://www.mssqltips.com/tip.asp?tip=1042

or

http://www.sqlteam.com/article/using-derived-tables-to-calculate-aggregate-values



回答3:

IMHO, an "inline view" is just another expression for a row-returning sub-query.

In other words — an SQL expression that could be replaced entirely by the name of a view (therefore, a correlated sub-query does not qualify as an inline view).



回答4:

This MSDN article claims that an inline view is another term for a derived table, and refers to the same thing everyone else is describing in this thread (subquery in FROM). An alternative in sql server 2005 and up is the common table expression.



回答5:

Another term often more commonly used for an inline view is 'Embedded Select Statement'

So a select inside a select.



回答6:

An inline view is a virtual table created in the from statement during the execution of the code/program



标签: sql tsql