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 > Database Server Software > DB2 > Can I use select inside a select??? If so how?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-25-06, 06:14
Paingiver Paingiver is offline
Registered User
 
Join Date: Feb 2004
Posts: 14
Can I use select inside a select??? If so how?

The select that I want using is like this....
Select (Select * from Databasename where Columnname = 'Value1' and Column2 is not null) from Databasename where Columnname <> 'Value'

DB2 version 8 I think

Thanks

Last edited by Paingiver; 08-25-06 at 06:40.
Reply With Quote
  #2 (permalink)  
Old 08-25-06, 06:28
Paingiver Paingiver is offline
Registered User
 
Join Date: Feb 2004
Posts: 14
I want to get value that have some complex condition like if Columnname = 'Value1' then Column2 is not null is the bellow sql possible?

Select * from Databasename where Columnname <> 'Value' and (if Columnname = 'Value1' then Column2 is not null)

Thanks
Reply With Quote
  #3 (permalink)  
Old 08-25-06, 08:32
umayer umayer is offline
Registered User
 
Join Date: Dec 2005
Posts: 273
How about:


Select *
from Databasename
where Columnname <> 'Value' and
(Columnname = 'Value1' and Column2 is not null or Columnname ^= 'Value1' )
Reply With Quote
  #4 (permalink)  
Old 08-25-06, 14:58
Peter.Vanroose Peter.Vanroose is offline
Registered User
 
Join Date: Sep 2004
Location: Belgium
Posts: 1,079
Quote:
Originally Posted by umayer
Select *
from Databasename
where Columnname <> 'Value' and
(Columnname = 'Value1' and Column2 is not null or Columnname ^= 'Value1')
Somewhat shorter:
Code:
Select * 
from   Databasename 
where  Columnname <> 'Value'
  and  (Column2 is not null or Columnname <> 'Value1')
This is a general logic conversion rule:
"if A then B" is equivalent with "(not A) or B".
__________________
--_Peter Vanroose,
__IBM Certified Database Administrator, DB2 9 for z/OS
__IBM Certified Application Developer
__ABIS Training and Consulting
__http://www.abis.be/
Reply With Quote
  #5 (permalink)  
Old 08-26-06, 08:49
Paingiver Paingiver is offline
Registered User
 
Join Date: Feb 2004
Posts: 14
Thanks for the replys.
Reply With Quote
  #6 (permalink)  
Old 08-28-06, 07:38
grofaty grofaty is offline
Registered User
 
Join Date: Jan 2003
Posts: 1,570
Hi,

if you would like to write select inside select you can write:
Select from (Select * from Databasename where Columnname = 'Value1' and Column2 is not null) as temp where Columnname <> 'Value'

Hope this helps,
Grofaty
Reply With Quote
  #7 (permalink)  
Old 08-28-06, 08:24
umayer umayer is offline
Registered User
 
Join Date: Dec 2005
Posts: 273
Quote:
Originally Posted by grofaty
Select from (Select * from Databasename where Columnname = 'Value1' and Column2 is not null) as temp where Columnname <> 'Value'
I disagree.

The correct nested table expression is:

Select from (Select * from Databasename where Columnname ^= 'Value1' or Column2 is not null) as temp where Columnname <> 'Value'
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