If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > SELECTing from a SELECT statement

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-23-04, 11:12
dinger dinger is offline
Registered User
 
Join Date: Feb 2004
Location: Baltimore, MD
Posts: 7
SELECTing from a SELECT statement

Is there a way to do this in straight SQL: Execute a SELECT query, then execute a SELECT query on the results of the first query?

Thanks.
Reply With Quote
  #2 (permalink)  
Old 03-23-04, 11:17
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,605
Assuming that your database engine supports derived tables, yes you can base one SELECT upon the results of another SELECT.

-PatP
Reply With Quote
  #3 (permalink)  
Old 03-23-04, 11:24
alligatorsql.com alligatorsql.com is offline
Registered User
 
Join Date: Jul 2001
Location: Germany
Posts: 189
Wink

Hello,

what do you think about

SELECT * FROM
(SELECT * FROM query1 WHERE TAB=1)
WHERE FIELD = 10;

Hope that helps ?

Best regards
Manfred Peter
Alligator Company Software GmbH
http://www.alligatorsql.com
Reply With Quote
  #4 (permalink)  
Old 03-23-04, 13:00
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,605
Don't you have to provide a table-alias for a derived table? I would expect you to need something like:
Code:
SELECT * FROM
   (SELECT * FROM query1 WHERE TAB=1) as A
   WHERE FIELD = 10;
for that to work.

-PatP
Reply With Quote
  #5 (permalink)  
Old 03-23-04, 14:09
alligatorsql.com alligatorsql.com is offline
Registered User
 
Join Date: Jul 2001
Location: Germany
Posts: 189
Cool Works without alias on many dbs

Hello,

this works also without an alias ... but when you want to join
its better to use an alias like

SELECT *
FROM (SELECT * FROM table1) AS a,
table2 b
WHERE a.id = b.id

Best regards
Manfred Peter
Alligator Company Software GmbH
http://www.alligatorsql.com
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On