Results 1 to 4 of 4
  1. #1
    Join Date
    Dec 2004
    Posts
    22

    Unanswered: Working With Multiple Queries

    I have 2 queries (A & B), each containing multiple joins. For every row returned by B, I need to check to see if there is a matching row returned by A (match on EntryID). If there is a match, I need to update a specific field.

    Can someone help me figure out how to set this up?

  2. #2
    Join Date
    Jan 2004
    Location
    Croatia, Europe
    Posts
    4,094
    Provided Answers: 4
    Basically, you want to do the update. That would be

    UPDATE some_table SET column = some_value WHERE condition;

    Can you include those queries into the 'condition'? Perhaps you could, but I guess it would be a giant condition having two queries, every containing multiple joins. Poor you if you try to put them together and poor everyone who'd try to debug this

    I'd, somehow, prefer doing this using procedural options your DB engine provides. If it was Oracle, I'd use PL/SQL procedure with a cursor loop (for your B query) and then - for every row it returns - check existence of a matching row returned by the A query and do the required update.

    Perhaps it is even possible to "join" those queries using EXISTS clause Oracle provides and do the job in the "condition" mentioned above ...

    Well, those were some thoughts. You'll surely hear some more and decide what's the best approach for your problem.

  3. #3
    Join Date
    Dec 2004
    Posts
    22
    Thanks for your reply. I'm using SQL Server. The Update is the easy part. The difficult part is finding the right juxtaposition of the 2 queries to accomplish what I want. Should I use a Subquery, or maybe WHERE EXISTS? Any thoughts?

  4. #4
    Join Date
    Dec 2004
    Posts
    22
    I managed to solve the problem by using WHERE IN:

    SELECT * FROM QueryA
    WHERE IN
    (QueryB)

Posting Permissions

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