0

In my mysql data is something like this

Name 1.0
Name 6.0
Name 5.2
Name 4.8
Name 10.00.258

now when I short that column it shows up like

Name 6.0
Name 5.2
Name 4.8
Name 1.0
Name 10.00.258

I want that 10 to be on top Is there any way around this?

3
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by desiguru
0

A proper table design would prevented this problem.

The first rule of relational database design:
- You should never store more than one piece of data in a single field.

Your fields are storing two pieces of information. A name and a number.

As a result, the number is being treated by MySQL as a string. And as a string, the *number* is being sorted one character at a time, placing 10 with 1.

If you were to split the number into it's own integer field, you could have MySQL sort the results based on the string first, and then the number. That way it would sort it by the entire number, not one char at a time.

I recommend you read this article. It describes the three basic rules of database design. Will help you avoid these sort of problems.

0

You have to SELECT statement and want to order it by a field which is a float.
So results is like....

2.05
2.3
2.4
2
Use order by ...

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.