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 > Compare multiple result sets

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-07-09, 14:31
anil_kodali anil_kodali is offline
Registered User
 
Join Date: Aug 2009
Posts: 1
Compare multiple result sets

How to compare multiple result sets with a set of values? Here is the scenario..

My query returns me multiple results(one column of data) and I want compare all the data at once with a set of data. For example my query returns 1,2,3 and I want compare the result set with (1,3), can I do that using a query with out using stored procedures? Obviously using the in clause isn't working(i.e., (1,2,3) in (1,3)), any other alternative.

Thanks,
Reply With Quote
  #2 (permalink)  
Old 08-07-09, 14:52
Stealth_DBA Stealth_DBA is offline
Registered User
 
Join Date: May 2009
Posts: 472
anil_kodali, one thing that comes to mind is two IN claues.
Code:
WHERE (
          VAL1 IN(SELECT COL1 FROM table-name WHERE...)
       OR 
          VAL2 IN(SELECT COL1 FROM table-name WHERE...)
      )
I don't know if you want either value (OR) in the list or both values (AND). You can adjust as needed.

You might try writing the SELECT COL1... in a Common Table Expression.
Reply With Quote
  #3 (permalink)  
Old 08-07-09, 15:23
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Depending on whether you are interested in matching or non-matching rows, you should use the INTERSECT or EXCEPT relational operator.
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