Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    May 2012
    Posts
    30
    Thanks
    10
    Thanked 1 Time in 1 Post

    Problum in MySQL query While using ORDER BY clause

    Hello Friends .
    i have a problum with MySQL query .
    i hav a table called "Products" with 'pID' , 'pTitle' , 'downloads' now i want to get the most downloaded product from the table .
    i wrote this line of query

    PHP Code:
    $sql mysql_query("SELECT * FROM Products ORDER BY downloads DESC LIMIT 1"
    its getting a product which have 99 downloads but there is more products which are downloaded more than 100 times .

    so basically i want to ask why the MySQL is assuming the 99 as Highest .


    i am using MySQL 5.0 and PHP 5.4

  • #2
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,337
    Thanks
    13
    Thanked 348 Times in 344 Posts
    which data type is downloads? because if you sort alphabetically (i.e. as strings) "99" > "100".
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • Users who have thanked Dormilich for this post:

    Azeem Hassni (09-16-2013)

  • #3
    New Coder
    Join Date
    May 2012
    Posts
    30
    Thanks
    10
    Thanked 1 Time in 1 Post
    thanks @Dormilich i have changed the data type to int now it's working fine .


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •