Quantcast
Channel: Forum Getting started with SQL Server
Viewing all articles
Browse latest Browse all 7129

Do not want to do a loop. Any insight/help?

$
0
0

Hello everyone, I am trying to do a query where I want to exclude a certain set of things(IDs/Numbers).

I am able to do a query like

select * 
from table 
where ID NOT IN 
(Select ID 
from table2 
where ID between 10 and 20)

With that query above, I'll be getting all entries where the ID is not in that range. 

My issue is that I want to include entries that CAN BE between those ranges if certain entries in Table 1 meet a certain criteria. I know I can loop through each entry and do it that way but I know that that is highly inefficient.

So what I'm trying to do is there is a third table somewhere else (Table3). If a row in Table 3 has an entry that has an ID that is outside the range of 10 and 20, then I want to include the entries that are between 10 and 20 for that one entry from Table1. If Table1 does not have any entries outside the range of 10 and 20 in Table3 (so all entries for Table1 in Table3 is between 10 and 20), I want to exclude those entries.

Is there anything else that I may be able to do?

Thanks!



Viewing all articles
Browse latest Browse all 7129

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>