DB2 Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesDB2 Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 14th, 2006, 02:35 PM
anaik100 anaik100 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2006
Posts: 2 anaik100 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 22 m 16 sec
Reputation Power: 0
Db2 sql query

query 1
select a from tab1 where a='xaa'

output:
1
2
3

query2
select b from tab2 where a=1
select b from tab2 where a=2
select b from tab2 where a=3

i want to build one query
and want the output in the format

b b b..

Please note that query1 will have 3 rows as output

Reply With Quote
  #2  
Old March 7th, 2006, 07:59 PM
vnquoi vnquoi is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2006
Posts: 3 vnquoi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 33 m 21 sec
Reputation Power: 0
query 1
select TOP 3 a from tab1 where a='xaa'

query2

select
case when a=1 then b else null end as b1
case when a=2 then b else null end as b2
case when a=3 then b else null end as b3
from tab2

output:
b1 b2 b3

Reply With Quote
  #3  
Old March 8th, 2006, 08:38 AM
Onslaught's Avatar
Onslaught Onslaught is offline
/(bb|[^b]{2})/
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Nov 2001
Location: Somewhere in the great unknown
Posts: 4,840 Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 2 Days 36 m 16 sec
Reputation Power: 88
Send a message via ICQ to Onslaught
TOP is not a db2 command. To limit the number of rows received use fetch first n rows only.

As far as the OP goes

you can either use a join on the two tables
i.e.
select tb.b from tab2 as tb inner join tab1 as ta on tb.a=ta.a where ta.a = 'xaa'

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesDB2 Development > Db2 sql query


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT