Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2009
    Posts
    1

    Unanswered: 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,

  2. #2
    Join Date
    May 2009
    Posts
    508
    Provided Answers: 1
    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.

  3. #3
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1
    Depending on whether you are interested in matching or non-matching rows, you should use the INTERSECT or EXCEPT relational operator.
    ---
    "It does not work" is not a valid problem statement.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •