Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

select from a select statement

Posted on 2009-12-16
8
Medium Priority
?
238 Views
Last Modified: 2012-05-08
Folks,
lets say I have a select statement that returns a table the way I want it.  How can I select from that table?

so Select * from (my table constructed from a select statement) where BlaBlaBla>2
0
Comment
Question by:sfun28
  • 3
  • 3
7 Comments
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 1600 total points
ID: 26064046
Select * from
(my table constructed from a select statement) A
where A.BlaBlaBla>2
0
 
LVL 4

Assisted Solution

by:justin-clarke
justin-clarke earned 400 total points
ID: 26064070
You can create a temporary table and then select from that...

Create the table with fields you want in it, and then directly insert the fields according to your select statement.

For example....

CREATE TABLE #tempTable1 (id INT IDENTITY,project_number VARCHAR(9),date DATETIME,comments VARCHAR(500))
INSERT INTO #tempTable1 (project_number,date,comments)
SELECT     ProjectRef,CostProfileComplete,Comments
FROM         tblProjectProfileTracker
WHERE     ((ProjectRef NOT IN (SELECT ProjNr FROM tblProjReportInfo)) AND
                  (Comments IS NOT NULL))
ORDER BY ProjectRef

SELECT * FROM #tempTable1

DROP TABLE #tempTable1
0
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 26064100
did you check my solution ?
0
Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

 
LVL 1

Author Comment

by:sfun28
ID: 26064104
sorry...i just asked to split the points.  I didn't see yours.
0
 
LVL 1

Author Comment

by:sfun28
ID: 26064125
actually your solution was better
0
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 26064133
>actually your solution was better

you dont really need to create a temptable here ,
0
 
LVL 1

Author Comment

by:sfun28
ID: 26064396
agreed.  i'm waiting for them to get back to me on my request for attention.  at that point I'll split the points since I already accepted the other solution. sorry!
0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
This shares a stored procedure to retrieve permissions for a given user on the current database or across all databases on a server.
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question