user618712
user618712

Reputation: 1523

sqlite query question

i'm messing around with sqlite. i've never messed with query languages or databases before. i made a little test database. it's a account database with accounts and id's. if i do the following, i get the max value:

SELECT MAX(balance)
FROM accounts

but how can i print ONLY the id of the account with the max balance?

thanks!

Upvotes: 1

Views: 119

Answers (3)

Michas
Michas

Reputation: 9428

I would use this:

    SELECT id FROM accounts ORDER BY balance DESC LIMIT 1;

Upvotes: 0

Paul Whitehurst
Paul Whitehurst

Reputation: 579

SELECT id 
FROM accounts
WHERE balance = (SELECT MAX(balance) from accounts)

Upvotes: 3

Dean Barnes
Dean Barnes

Reputation: 2272

Have you tried?:

SELECT id FROM accounts WHERE balance = MAX(balance)

Upvotes: 0

Related Questions