SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Thread: sorting

  1. #1
    SitePoint Enthusiast
    Join Date
    Sep 2008
    Posts
    99
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    sorting

    hi all ,

    i have two tables , first one for companies , and second one for companies offers :

    companies table design is :
    company name company type

    offers table
    id company_name offer_name speed price cap_limit offer_date

    how it will be the query to sort , min price and max speed , or max cap_limit and min price ...i want the user will sort offer depend on multi criteria

    i hope u got me , thanks a lot guys

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,496
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    First of all, I'd add a company id column to the companies table, and use that id as the foreign key in the offers table.

    About your question, you can sort on multiple fields, but of course it will sort on one field, and then within each value of that first field, it will sort on the second field, ecc.
    So what exactly do you mean when you say "to sort min price and max speed"? Can you give a data example?

  3. #3
    SitePoint Enthusiast
    Join Date
    Sep 2008
    Posts
    99
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i have list of companies , and i want to sort companies who have cheapest price , and highest speed and so on

  4. #4
    SitePoint Member
    Join Date
    Aug 2012
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry, I didn't understand your query...

  5. #5
    SitePoint Enthusiast
    Join Date
    Sep 2008
    Posts
    99
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    company_name type
    x 3g
    y wimax


    id company_name offer_name speed cap_limit price offer_date
    1 x xx1 6M 100GB 10.00 date
    2 x xx2 5M 90GB 9.00 date
    3 x xx3 5M 80GB 8.00 date
    3 y yy1 6M 90GB 11.00 date

    if i want to sort by minimum price then hieghest speed for each company

    it will be:
    3 x xx3 8.00 5M 90GB
    2 x xx2 9.00 5M 80GB
    ...

  6. #6
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,496
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    It looks like all you need is an ORDER BY clause. Please take a look at the manual: http://dev.mysql.com/doc/refman/5.5/en/select.html

  7. #7
    SitePoint Enthusiast
    Join Date
    Sep 2008
    Posts
    99
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    can i say .. order by price ASC , speed Desc ..... ?

  8. #8
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,251
    Mentioned
    59 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by mnask79 View Post
    can i say .. order by price ASC , speed Desc ..... ?
    yes, you can say that

    but i think you oughta test it first, so you know how it works
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


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
  •