abidinberkay
abidinberkay

Reputation: 2025

SQLite: Selecting the maximum corresponding value

I have a table with three columns as follows:

id INTEGER    name TEXT    value REAL

How can I select the value at the maximum id?

Upvotes: 10

Views: 22925

Answers (4)

sergi
sergi

Reputation: 21

Try this:

    SELECT value FROM table WHERE id==(SELECT max(id) FROM table));

Upvotes: 1

CL.
CL.

Reputation: 180240

Get the records with the largest IDs first, then stop after the first record:

SELECT * FROM MyTable ORDER BY id DESC LIMIT 1

Upvotes: 20

Lian
Lian

Reputation: 1629

Just like the mysql, you can use MAX()

e.g. SELECT MAX(id) AS member_id, name, value FROM YOUR_TABLE_NAME

Upvotes: 6

Abdennour TOUMI
Abdennour TOUMI

Reputation: 93511

If you want to know the query syntax :

String query = "SELECT MAX(id) AS max_id FROM mytable";

Upvotes: 0

Related Questions