Reputation: 1523
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
Reputation: 9428
I would use this:
SELECT id FROM accounts ORDER BY balance DESC LIMIT 1;
Upvotes: 0
Reputation: 579
SELECT id
FROM accounts
WHERE balance = (SELECT MAX(balance) from accounts)
Upvotes: 3
Reputation: 2272
Have you tried?:
SELECT id FROM accounts WHERE balance = MAX(balance)
Upvotes: 0