Nyaruko
Nyaruko

Reputation: 4459

SQLite and range query

How could I perform a simple range query in SQLite efficiently?

Say, I have data that saves a person information and I want to find the people with age between 20~45, and weight between 50~80kg?

What should I do (like setting certain index?) to make the searching more efficient?

Upvotes: 1

Views: 4022

Answers (2)

Phantômaxx
Phantômaxx

Reputation: 38098

I'd try something like

SELECT PersonName FROM Persons WHERE (Age BETWEEN 20 AND 45) AND (Weight BETWEEN 50 AND 80)

Indexing the fields Age and Weight would help speeding up the query.

Here's a nice overview about indexing in SQLite: http://www.tutorialspoint.com/sqlite/sqlite_indexes.htm

Upvotes: 3

CL.
CL.

Reputation: 180060

SQLite's documentation for the R-tree module says:

An R-Tree is a special index that is designed for doing range queries.

Upvotes: 7

Related Questions