Large WHERE query
What is the best way to query a database with a large set of up to 500 comparisons per row.
SELECT * FROM table WHERE column = x OR column = y OR column = z OR ...(x500)
I estima开发者_StackOverflow社区te that the table could grow to up to thousands of entries in the short term. Thanks
Use WHERE column IN(x,y,z...)
If you are doing a few... say less than 20 or so, you could use an IN (....) clause. However, if you are doing something that will normally span 100's or 1000's on a regular basis, I would use a temp table of just "columnX" values and insert into that all the possible values... then query a join using this temp table as basis to the other...
select YT.*
from
JustValuesTable JVT
Join YourTable YT
ON JVT.ColumnX = YT.ColumnX
rest of query...
maybe you can use the in clause ..
select * from table where column in ('asdf', 'aqwer' .....)
additional, you may want to create a view, containing your allowed values, and then
select * from table where column in (select your_field_name from your_view)
You may be better off using an IN
query:
SELECT * FROM table WHERE column IN (x, y, z)
That would make it a little more readable at least and I think should improve performance.
How about using the IN function?
精彩评论