开发者

SQLite : INSERT and ORDER in the same time

I have a table with 25.000 rows (columns with strings).

I would like to improve my select query. "SELECT name FROM table WHERE name LIKE 'something' ORDER BY name LIMIT 15"

开发者_StackOverflow中文版

The database will be static.

I would like to know if it's possible to order a column when I am inserting a row in my table and if it will reduce the time of the select query if the table is already order by name ?


What you're asking doesn't make sense - the ORDER clause only applies to SELECT, not INSERT operations. (What would you order for example?)

If you're talking about building some form of index, as long as you've specified that the name column is an index (ideally when constructing the table) there's not a lot else you can do - it's up to the authors of the RDBMS system to handle the rest. (i.e.: They decide when indexes are constructed/updated, etc. - you can't control this.)


If the database will be static why use it at all? Just hardcode those 15 names in the program. If you mean that the table will not be changing then to improve your query you can put an index on name column name or use more amount of cache.


Something like the following will work:

INSERT INTO TABLE1 (S1, S2, S3) SELECT S1, S2, S3 FROM TEMP ORDER BY S1, S2, S3

Here the ordering is done as part of the SELECT statement before insertion.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜