Collections:
Using Subqueries in the FROM Clause in SQL Server
How To Use Subqueries in the FROM Clause in SQL Server?
✍: FYIcenter.com
If you have a query returning many rows of data, and you want to perform another query on those rows, you can put the first query as a subquery in the FROM clause of the second query. A subquery used in this way become a temporary table, and you must provide a table alias name for the subquery as in "SELECT ... FROM (SELECT ...) aliasName". The following statement shows you how to use a subquery as base table for the main query:
SELECT * FROM (SELECT l.id, l.url, r.comment FROM fyi_links l LEFT OUTER JOIN fyi_rates r ON l.id = r.id) WHERE url LIKE '%er%' GO Msg 156, Level 15, State 1, Line 3 Incorrect syntax near the keyword 'WHERE'. SELECT * FROM (SELECT l.id, l.url, r.comment FROM fyi_links l LEFT OUTER JOIN fyi_rates r ON l.id = r.id) s WHERE s.url LIKE '%er%' GO 101 dev.fyicenter.com The best 102 dba.fyicenter.com Well done 103 sqa.fyicenter.com Thumbs up 107 www.winrunner.com NULL
The error on the first query is caused by the missing alias name to name output of the subquery as a temporary table.
⇒ Counting Groups Returned with the GROUP BY Clause in SQL Server
⇐ Using Subqueries with the EXISTS Operators in SQL Server
⇑ Using SELECT Statements with Joins and Subqueries in SQL Server
2016-10-29, 1498🔥, 0💬
Popular Posts:
How To Insert New Line Characters into Strings in SQL Server Transact-SQL? If you want to break a st...
How To Fix the INSERT Command Denied Error in MySQL? The reason for getting the "1142: INSERT comman...
What is SQL Server Transact-SQL (T-SQL)? SQL Server Transact-SQL, also called T-SQL, is an extension...
What Is SQL*Plus in Oracle? SQL*Plus is an interactive and batch query tool that is installed with e...
How Fixed Length Strings Are Truncated and Padded in SQL Server Transact-SQL? When the length of the...