开发者

SQLite Select an id which is smaller than a number

开发者 https://www.devze.com 2022-12-31 04:25 出处:网络
I am trying to only select the objects where the id is smaller than an int value. e.g.: i have 3 objects -> id = 1, id = 2, id = 3

I am trying to only select the objects where the id is smaller than an int value.

e.g.: i have 3 objects -> id = 1, id = 2, id = 3 Now I want to only get the 开发者_JAVA技巧 objects with the id smaller than the variable i = 2;

How can I manage this?

sql = "SELECT id FROM table_name WHERE id <= i";

Thanks ;-)


I am using SQLite3 on iPhone OS. When I do:

SELECT id FROM table_name WHERE id <= 2

it works... but the problem is the variable i!


SQLite supports standard SQL syntax for parameterized queries, so one of the following will be useful:

SELECT id FROM table_name WHERE id <= ?
SELECT id FROM table_name WHERE id <= :i

The first uses a positional parameter (the ?) and the second a named parameter (i). How those are bound in your host language we can't tell you; we don't know what lang you are using!

0

精彩评论

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