Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Old Forums
 CLOSED - General SQL Server
 select * from (select)

Author  Topic 

casati74
Posting Yak Master

109 Posts

Posted - 2006-09-01 : 10:40:16
Hello,
it possible, and if it's possible how, to write a select for retrive information using another select how from statement???


es:

select * from (select miatabella from nomitabelle where id =1)
where desc='prova'

It's possible????

nr
SQLTeam MVY

12543 Posts

Posted - 2006-09-01 : 10:45:10
Yes - it's called a derived table. You just have to give it an alias and include the columns referenced

select *
from (select miatabella, desc from nomitabelle where id =1) a
where desc='prova'


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2006-09-01 : 10:46:51
yes, this is called derived table. In the example you gave, field Desc must be present in the inner query then only you can refer it in the outer query, like this..

select * from (select miatabella,desc from nomitabelle where id =1)
where desc='prova'


Harsh Athalye
India.
"Nothing is Impossible"
Go to Top of Page

casati74
Posting Yak Master

109 Posts

Posted - 2006-09-01 : 10:49:14
Thank's a lot!!!!!!!!!!!!!!!!!!!
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-09-02 : 10:13:42
quote:
Originally posted by harsh_athalye

yes, this is called derived table. In the example you gave, field Desc must be present in the inner query then only you can refer it in the outer query, like this..

select * from (select miatabella,desc from nomitabelle where id =1)
where desc='prova'


Harsh Athalye
India.
"Nothing is Impossible"


Also, You need to use Alias for derived table. Refer Nigel's query

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2006-09-02 : 10:28:14
quote:
Originally posted by madhivanan
Also, You need to use Alias for derived table. Refer Nigel's query

Madhivanan

Failing to plan is Planning to fail



Oops!!!

Yeah, I just missed it, Thanks Madhivanan !!

Harsh Athalye
India.
"Nothing is Impossible"
Go to Top of Page
   

- Advertisement -