Whats is efficient database design in sqlite when I only need to insert and retrieve smallest entry in an integer column?

Basically I need a min-heap functionality with sqlite as my data storage. Lets say I need a table with 2 columns. 1st is unique ids and 2nd is integer value. I always need the the id with smallest integer value.

Any suggestions ??

Answers


You get that for free on indexed columns

  CREATE TABLE table(
     one INTEGER PRIMARY KEY,
     two INTEGER
  );
  CREATE INDEX table_two ON table(two);

  INSERT ...

  SELECT MIN(two) FROM table;

Need Your Help

MySql : Order by and Group By combining not giving the latest record

php mysql sql

Using the following query I am looking for a solution to get the latest record that having some conditions.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.