Results 1 to 9 of 9
  1. #1
    Join Date
    Dec 2008
    Posts
    99

    Unanswered: order values in the column

    Hello
    I have this output.If I export this in excell,with pivot table I can change the order of values in columb as I wish,is there a way to do this with sql
    Best Regards

    COLUMNA COLUMNB
    city M*
    city d*
    city o*
    city s*
    city Mn*
    city do*
    city MT*
    city My*

  2. #2
    Join Date
    Jun 2003
    Location
    West Palm Beach, FL
    Posts
    2,713

    Cool order it:

    Try:
    Code:
    SELECT   columna columnb
        FROM mytable
    ORDER BY columna, columnb;
    The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb

  3. #3
    Join Date
    Dec 2008
    Posts
    99
    Quote Originally Posted by LKBrwn_DBA
    Try:
    Code:
    SELECT   columna columnb
        FROM mytable
    ORDER BY columna, columnb;
    I want to decide on the order,this is listing of a-z or z-a, for example I want to list my* listed before do* or m*,
    Best Regards

  4. #4
    Join Date
    Jun 2003
    Location
    West Palm Beach, FL
    Posts
    2,713

    Cool Asc/Desc

    Use the Asc(ending)/Desc(ending) option of the ORDER BY clause.
    The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb

  5. #5
    Join Date
    Mar 2007
    Posts
    623
    Quote Originally Posted by sunsail
    for example I want to list my* listed before do* or m*
    And what is the logic behind that list order?
    If you want to order by the length of COLUMNB, use LENGTH function.
    Otherwise, be more precise, please.

  6. #6
    Join Date
    Dec 2008
    Posts
    99
    Quote Originally Posted by flyboy
    And what is the logic behind that list order?
    If you want to order by the length of COLUMNB, use LENGTH function.
    Otherwise, be more precise, please.
    That is my problem,there is not any logic.User keeps it changing all the time and creating combination of these values.That's why I have to order them in pivot table.
    I just want to if there is a way to order these values freely,like put x value at 1st place y value at 2nd etc then next week, x at 3rd place y at 5th place

    I hope I have explained myself clear.
    Best Regards

  7. #7
    Join Date
    Dec 2008
    Posts
    99
    Quote Originally Posted by LKBrwn_DBA
    Use the Asc(ending)/Desc(ending) option of the ORDER BY clause.
    "this is listing of a-z or z-a" I think we talk about the same.

  8. #8
    Join Date
    Jun 2009
    Posts
    11

    Cool fine

    Quote Originally Posted by sunsail
    Hello
    I have this output.If I export this in excell,with pivot table I can change the order of values in columb as I wish,is there a way to do this with sql
    Best Regards

    COLUMNA COLUMNB
    city M*
    city d*
    city o*
    city s*
    city Mn*
    city do*
    city MT*
    city My*

    Hi sunsail,
    Is your question is about changing the row order?
    i.e.,
    city o*
    city M*
    city d*
    ....

    (or) just order by a,b,c....z / z,y....a?
    please forward is this ur question or else please make more clear.

  9. #9
    Join Date
    Jun 2004
    Location
    Liverpool, NY USA
    Posts
    2,509
    if there is no pattern to the order, then you need to add another column to the table that would only be used to sort by. then

    Code:
    SELECT   columna columnb
    FROM mytable
    ORDER BY sort_column;
    Bill
    You do not need a parachute to skydive. You only need a parachute to skydive twice.

Posting Permissions

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