2

enter image description here

I have above table and I want to get the highest value from table bids where bid_id=60 using the following query

SELECT MAX(offer_amount) as maz FROM bids WHERE bid_id = 60

The problem is I'm getting the result as 80 in instead of the correct value which is 7000000

Anybody with an idea of how to solve this?

Jonathan Leffler
759k145 gold badges961 silver badges1.3k bronze badges
asked Sep 8, 2016 at 6:27
5
  • Aberrant case. Would you please share an sql fiddle ? Commented Sep 8, 2016 at 6:30
  • 5
    It's "correct". And store integers as integers and strings as strings Commented Sep 8, 2016 at 6:31
  • @Strawberry it have worked I have changed the amount_column from VARCHAR to INT Commented Sep 8, 2016 at 6:39
  • Well, of course;-) Commented Sep 8, 2016 at 6:41
  • You can get desired output by using CAST but what about if you perform SUM, AVG function in that column again you have to use CAST where ever you need and it's not correct way. Commented Sep 8, 2016 at 6:42

1 Answer 1

6

Store offer_amount in a numeric field (such as integer or decimal), not as text. Quick solution is to use the CAST() function in the query to cast the field's data type to a numeric one.

answered Sep 8, 2016 at 6:31
Sign up to request clarification or add additional context in comments.

3 Comments

And we can tell it's a string, not a number, because the values are left-justified in the displayed fragment of the table.
Quick solution is to add 0 to the value
Changing offer_amount from VARCHAR to INT have worked. Thank you guys

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.