I've got two queries (actually one of those is a union of two distinct queries but the output is effectively one) that are just lists of id values.
I.e. list1 and list2
I want to check whether any of the values in list1 exists in list2 IF list2 contains any values at all.
I.e. if list2 contains any values (and it might not) if at least one of those values is also present in list1 then all is okay.
If list2 contains no values then we are also okay, irrespective of list1.
However, if list2 contains values but list1 is empty or none of the values in list1 is also in list2 then we have an issue.
Now, I can do this with two separate queries and programatic logic outside of the queries to check, if list2 has values, whether any of the values in list1 matches or not BUT is there any way I can do all of this in a single query with the result of the query being, for example, 0 or 1 to denote whether there is an issue or not...?
Was thinking of some sort of outer join and case statements but just can't get my head around the logic of it...
Any help truly appreciated!
I.e. list1 and list2
I want to check whether any of the values in list1 exists in list2 IF list2 contains any values at all.
I.e. if list2 contains any values (and it might not) if at least one of those values is also present in list1 then all is okay.
If list2 contains no values then we are also okay, irrespective of list1.
However, if list2 contains values but list1 is empty or none of the values in list1 is also in list2 then we have an issue.
Now, I can do this with two separate queries and programatic logic outside of the queries to check, if list2 has values, whether any of the values in list1 matches or not BUT is there any way I can do all of this in a single query with the result of the query being, for example, 0 or 1 to denote whether there is an issue or not...?
Was thinking of some sort of outer join and case statements but just can't get my head around the logic of it...
Any help truly appreciated!