Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a query to list a set of numbers, for example 1000000 through 2000000, I then run another query in that while loop to see if it matches another table in another database. This part runs fine, but a little slow.

I then need to have another query such that if it returns false, then it does another check on yet another table. The problem I'm having though, is that the check in this table is not as simple as a match.

The table structure on last table is like this:

  • firstnum
  • secondnum

This is intended for use in a range of numbers. So row 1 for example might be:

1000023, 1000046

This would mean it's for all numbers between and including those values. There are thousands of these entries in the DB, and I'm trying to figure out the best way to determine if that particular number I'm searching on exists in that table somewhere, but since it's not a direct match, I'm not sure how to accomplish this. The table is also PostgreSQL while the main queries are MySQL.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
159 views
Welcome To Ask or Share your Answers For Others

1 Answer

It's a bit hard to understand what you're trying to say, but I'm afraid the solution is ridiculously simple: ... WHERE firstnum <= X AND X <= secondnum, where X is the number you are looking for.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...