Walshy
Walshy

Reputation: 850

Get biggest value from column

I want to get the biggest value from a column called amount, I tried using the MAX in the query but it did not get the largest one.

SQL Query:

SELECT MAX(amount) FROM games;

My table (Amount column):

+--------+
| amount |
+--------+
| 10     |
| 100    |
| 1      |
| 50     |
| 954    |
| 5      |
| 1000   |
| 90000  |
| 7      |
| 10     |
+--------+

Output:

+-------------+
| MAX(amount) |
+-------------+
| 954         |
+-------------+

Is there a reason why it is not getting the largest value possible?

Upvotes: 0

Views: 55

Answers (2)

Hossein
Hossein

Reputation: 1391

it is because of field type in your database. if the type of column be a numeric type like int or etc , the MAX function works fine, otherwise you muse use other solutions.

Upvotes: 0

Denis Leger
Denis Leger

Reputation: 223

As said in the comments, the type is probably not right.

To see if it is the problem, you can convert directly using mysql:

SELECT MAX(CONVERT(amount, SIGNED)) FROM games;

Upvotes: 4

Related Questions