title: How to see if a value exists on multiple tables, and exclude tables who do not have any values
body: <p>I am trying to write part of a stored procedure where there are 4 tables (for this example, I will call them @A, @B, @C and @D - each table only has one column named id and it is type int). I want to pull the cases where the values on the tables match eachother, but only if the tables have items on them. These tables have to do with a data filter in my application, so if there is no value on the tables, that filter is not applied. This part of the stored procedure will tell me which values exists on all the tables where the filter is applied so the right data from the combo of filter options is displayed. I was doing this with nested if statements if count(id) from the table was > 0, but there are too many combinations and the procedure runs extremely slow, lagging my application. </p>
  
  <p>So for a better example lets say table @A, @C, and @D have values in them, but table @B does not. I need to find a way to get all the values that exist on all 3 tables. I would also need to do this if only 2 tables had items, or 1, or all 4. Again the nested if approach is too slow and lags out the application. Does anyone have a better idea/approach for this issue? Thanks in advance.</p>