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?
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.
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?