IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Inline views from lists which have a certain combination


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
harisukumaran

New User


Joined: 14 Jun 2005
Posts: 75

PostPosted: Thu Nov 23, 2006 2:10 am
Reply with quote

Hello Everybody,
Is it possible to obtain rows from a table which have a certain combination
of values in 2 columns.
I know I could do
Code:
---------------------------------------------------
select * from table1
where
(column1 = 1111 and column2 = 2222)
or
(column1 = 3333 and column2 = 4444)
or
...
...
...

----------------or------------------------------
select * from table1
where digits(column1) concat digits(column2)
in
('11112222',
 '33334444',
 ...
 ...
 ...
)

But hey! there must be a cleaner way to do this! It is not a rare requirement

I mean something like this(although it is not syntactically correct):

Code:
select * from table1
where
column1,column2
in
((1111,2222),
 (3333,4444),
...
...
...

)

After all DB2 V8 supports queries like

Code:
select * from table1
where (column1,column2)
in
(
select column1,column2
from table1
group by
column1,column2
having count(distinct column3) > 1
)
Back to top
View user's profile Send private message
priyesh.agrawal

Senior Member


Joined: 28 Mar 2005
Posts: 1448
Location: Chicago, IL

PostPosted: Thu Nov 23, 2006 9:15 am
Reply with quote

Hi Hari,

We can try something like this...
Code:
SELECT *
FROM CREATORID.TABLE-NAME
WHERE CONCAT(COLUMN1,COLUMN2) IN
(
'11112222',
'33334444',
);

But one thing needs to be noticed here that, values given in "IN" clause should exactly match as a combination of COLUMN1 & COLUMN2.
Lets say if values are:-
Column1 C(5) = '1111$' ($= Space)
Column2 C(5) = '2222$' ($= Space)
then value set in "IN" clause should have a value like "1111$2222$" ($= Space)

HTH.
Back to top
View user's profile Send private message
kgumraj

Active User


Joined: 01 May 2006
Posts: 151
Location: Hyderabad

PostPosted: Thu Nov 23, 2006 2:16 pm
Reply with quote

One more thing to add to priyesh is you can give "Like" to get the data when you are not sure about the exact value.

Ex:
select * from table1
where col1 like 'filed%';
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts DB2 Views with Multiple SQL & Col... DB2 8
No new posts Sort counter to show records combination JCL & VSAM 2
No new posts SMS:- Efficient filter lists in ACS All Other Mainframe Topics 7
No new posts Need help on DB2 compound SQL or Inli... DB2 3
No new posts Extract data from n DB2 Views automat... All Other Mainframe Topics 5
Search our Forums:

Back to Top