dbTalk Databases Forums  

SQL 2005 Querying Question

microsoft.public.sqlserver.mseq microsoft.public.sqlserver.mseq


Discuss SQL 2005 Querying Question in the microsoft.public.sqlserver.mseq forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Milo
 
Posts: n/a

Default SQL 2005 Querying Question - 05-18-2009 , 02:29 AM







Is it possible to SELECT query from the result of a select query, without
creating temp table? and how any reference?

example:

ie... select * from (<select statement>)



many thanks.

--
Milo


Reply With Quote
  #2  
Old   
Russell Fields
 
Posts: n/a

Default Re: SQL 2005 Querying Question - 05-18-2009 , 09:13 AM






Milo,

This is called a derived table and can be code as:

SELECT * FROM (SELECT * FROM A_Table) AS Derived_Table

The derived table inside the ( ) can be of arbitrary complexity. A simple
example:

SELECT * FROM
(SELECT c.CustomerID,
SUM(r.Receipts) AS TotalReceipts,
MAX(r.ReceiptDate) AS MostRecentReceiptDate
FROM SalesReceipts r
JOIN Customers c ON r.CustomerID = c.CustomerID
WHERE c.CustomerActive = 1
GROUP BY CustomerID) AS Derived_Table

RLF

"Milo" <anisha (AT) indiamail (DOT) com> wrote

Quote:
Is it possible to SELECT query from the result of a select query, without
creating temp table? and how any reference?

example:

ie... select * from (<select statement>)



many thanks.

--
Milo



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.