|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
AT&T devCentral & BlackBerry(r) Webcast Series: BlackBerry and GPS -Build Location Awareness into your BlackBerry Applications, July 10th-1:00PM EST. Register Today!
|
|
#1
|
|||
|
|||
|
Db2 sql query modified version query
hi guys,
my requirement has changed a little so i am putting it in a new post... first requirement SELECT * FROM tab1 a,tab2 b WHERE a.ID='b.col1+b.col2' i want to append two columns data to form a where clause of the query.. i am trying to put it in DB2..but not successfull..any help second requirment my first query gives me the output as colA, colB select colA,colB from tab1 where colC='XXX' no my second query i write to get the value of colA,colB select * from tab2 where col1=colA select * from tab2 where col1=colB NOW I WANT TO DO THIS FROM A SINGLE QUERY |
|
#2
|
||||
|
||||
|
Hi Anaik
Your first requirement seems like a concatenation. The way to code that in DB2 is: Quote:
If that assumption is incorrect, you have to convert the numeric columns to characters using the function CHAR(), e.g.: Quote:
Now regarding your second requirement: I assume there is an OR-relation between the SELECTS on tab2. I suggest either a subselect: Code:
SELECT *
FROM tab2
WHERE col1 IN
(SELECT colA from tab1 where colC='XXX')
OR col1 IN
(SELECT colB from tab1 where colC='XXX')
;
Code:
SELECT b.*
FROM tab1 a
, tab2 b
WHERE (b.col1 = a.colA OR b.col1 = a.colB)
AND a.colC = 'XXX'
;
Your choice may depend on the importance of:
may yield some duplicate values in cases where colA and colB have the same value within the same row. The OR in both my queries will reduce the two resultvalues to one row, whereas your example will produce that resultvalue in both the queries on tab2, and you would end up with more resulting rows. If that really is a problem please let me know. Regards, Jaap. 19'3/112 |
![]() |
| Viewing: Dev Shed Forums > Databases > DB2 Development > Db2 sql query modified version query |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|