1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

need to solve mysql query

Discussion in 'PHP' started by zappak, Oct 19, 2013.

  1. #1
    hello friend.

    need solve order by follwing format

    a. street
    b. city
    c. state
    d. zip

    I'm using this code but it's not ordering what i want.

    SELECT *
    FROM test
    ORDER BY a, b, c, d ASC ;

    it's only ordering street colm.

    any help?
     
    Solved! View solution.
    zappak, Oct 19, 2013 IP
  2. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #2
    What result do you want? Ie, as long as you sort by street first, it will sort on street. Then city (if the same street is in two or more cities) and so on.
     
    PoPSiCLe, Oct 19, 2013 IP
    ThePHPMaster likes this.
  3. Devang Tadvi

    Devang Tadvi Greenhorn

    Messages:
    1
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    21
    #3
    here you are trying to sort multiple colm in one single query .
    your query is wrong try multi-level sub query
     
    Devang Tadvi, Oct 19, 2013 IP
    kamleshnishad likes this.
  4. rehan.khalid.9235

    rehan.khalid.9235 Active Member

    Messages:
    78
    Likes Received:
    2
    Best Answers:
    1
    Trophy Points:
    85
    #4
    hi, try this

    SELECT *
    FROM test
    ORDER BY a ASC,b ASC,c ASC,d ASC

    * for records with same 'a' (street) it will then sort by 'b'(city) and so on..
     
    rehan.khalid.9235, Oct 20, 2013 IP
  5. zappak

    zappak Active Member

    Messages:
    366
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    80
    #5
    for example..
    street a city b state e zip a
    street c city d state a zip c
    street b city c state c zip f
    street b city c state c zip b
    street a city c state c zip b
    street a city d state e zip a

    result should be
    street a city b state e zip a
    street a city c state c zip b
    street a city d state e zip a
    street b city c state c zip b
    street b city c state c zip f
    street c city d state a zip c

    it should be like 1st street sort. then city sort along with street then state along with street and city also same with zip ..
     
    zappak, Oct 20, 2013 IP
  6. zappak

    zappak Active Member

    Messages:
    366
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    80
    #6
    already tried. it's only sorting street only. one colm
     
    zappak, Oct 20, 2013 IP
  7. zappak

    zappak Active Member

    Messages:
    366
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    80
    #7
    it should works like

    data
    street a,city b,state e,zip a
    street c,city d,state a,zip c
    street b,city c,state c,zip f
    street b,city c,state c,zip b
    street a,city c,state c,zip b
    street a,city d,state e,zip a

    result
    street a,city b,state e,zip a
    street a,city c,state c,zip b
    street a,city d,state e,zip a
    street b,city c,state c,zip b
    street b,city c,state c,zip f
    street c,city d,state a,zip c
     
    zappak, Oct 20, 2013 IP
  8. rehan.khalid.9235

    rehan.khalid.9235 Active Member

    Messages:
    78
    Likes Received:
    2
    Best Answers:
    1
    Trophy Points:
    85
    #8
    share your some sample data, i will check the query on that
     
    rehan.khalid.9235, Oct 20, 2013 IP
  9. zappak

    zappak Active Member

    Messages:
    366
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    80
    #9
    can you write query like order by a ASC ( order by b ASC ( order by c ASC ( order by d ASC ) ) ) ???
     
    zappak, Oct 20, 2013 IP
  10. #10

    i created a dumy table, entered your data and run my query. i got the result 100% accurate. check the attach image:-
    [​IMG]
     
    rehan.khalid.9235, Oct 20, 2013 IP
    ryan_uk likes this.
  11. ThePHPMaster

    ThePHPMaster Well-Known Member

    Messages:
    737
    Likes Received:
    52
    Best Answers:
    33
    Trophy Points:
    150
    #11
    What is your table structure?

    Also post the EXACT data you have so we can figure it out.
     
    ThePHPMaster, Oct 22, 2013 IP
  12. zappak

    zappak Active Member

    Messages:
    366
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    80
    #12
    thanks all mate.
    got it done.
     
    zappak, Oct 25, 2013 IP