|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
|
#2
|
|||
|
|||
|
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 |
|
#3
|
||||
|
||||
|
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' |
![]() |
| Viewing: Dev Shed Forums > Databases > DB2 Development > Db2 sql query |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|