SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Old Forums
 CLOSED - General SQL Server
 select * from (select)
 Forum Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

casati74
Posting Yak Master

Italy
109 Posts

Posted - 09/01/2006 :  10:40:16  Show Profile
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

United Kingdom
12543 Posts

Posted - 09/01/2006 :  10:45:10  Show Profile  Visit nr's Homepage
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
Flowing Fount of Yak Knowledge

India
5509 Posts

Posted - 09/01/2006 :  10:46:51  Show Profile  Visit harsh_athalye's Homepage  Click to see harsh_athalye's MSN Messenger address  Send harsh_athalye a Yahoo! Message
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

Italy
109 Posts

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

madhivanan
Premature Yak Congratulator

India
22713 Posts

Posted - 09/02/2006 :  10:13:42  Show Profile  Send madhivanan a Yahoo! Message
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
Flowing Fount of Yak Knowledge

India
5509 Posts

Posted - 09/02/2006 :  10:28:14  Show Profile  Visit harsh_athalye's Homepage  Click to see harsh_athalye's MSN Messenger address  Send harsh_athalye a Yahoo! Message
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
  Previous Topic Topic Next Topic  
 Forum Locked
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000