SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot
    Join Date
    Oct 2008
    Posts
    155
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Find the three smallest values

    Hello,

    I have a table that looks like this

    Destination | Cost | Car


    Atlanta | 5 | 23
    Atlanta | 1 | 64
    Atlanta | 4 | 42
    Atlanta | 8 | 49

    I need to do a query where I need to find the 3 cars that cost the least for the user where desitnation='atlanta'

    The result should be something like this

    Car 64 : 1
    Car 42 : 4
    Car 23 : 5

    Please help, this has got me stuck.

    Thanks.

  2. #2
    SitePoint Addict
    Join Date
    Sep 2007
    Posts
    371
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here's the query, format it in php :

    Code MySQL:
    SELECT Car, Cost
    FROM CarTable 
    WHERE Destination = 'Atlanta'
    ORDER BY Cost ASC 
    Limit 0, 3


Bookmarks

Posting Permissions

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