zeliboba_fett
zeliboba_fett

Reputation: 55

How do I get PRIMARY KEY from database using another column's value? (Android, SQLite)

I've got a table with id INTEGER PRIMARY KEY AUTOINCREMENT column and NAME VARCHAR column. And I know the value of the NAME column.

How do I retrieve id of the row that contains the value?

Upvotes: 0

Views: 498

Answers (2)

Alex Lockwood
Alex Lockwood

Reputation: 83303

If you are using a ContentProvider, you would do something along the lines of

getContentResolver().query(CONTENT_URI, null, "name_col = ?", new String[] { "name" }, null);

Upvotes: 0

Codeman
Codeman

Reputation: 12375

my SQLite is rusty, but something along these lines should work:

SELECT id FROM table WHERE name IS myVar

Hope this helps.

Upvotes: 2

Related Questions