Results 1 to 5 of 5
  1. #1
    Join Date
    Nov 2003
    Location
    Sinapore
    Posts
    187

    Unanswered: Sort words from different columns...

    Hi,

    Let's you've a database of words as follows:
    Code:
    column1    column2    column3
    cheer        town          greed
    occupy      serene       addicted
    provide     astute        recoup
    The words are fed into the database in no particular order. Is there a way to select all the words from the 3 columns and sort them aphabatically with a mysql query? In order words, the output of the select should be:

    addicted
    astute
    cheer
    greed
    occupy
    provide
    recoup
    serene
    town

    (I'm using 4.0.16 so subset is not an option.)

    Hope someone can enlighten me

    TIA

  2. #2
    Join Date
    Nov 2003
    Posts
    91
    select column1 from yourtable
    union
    select column2 from yourtable
    union
    select column3 from yourtable
    order by 1;

  3. #3
    Join Date
    Nov 2003
    Location
    Sinapore
    Posts
    187
    Originally posted by vanekl
    select column1 from yourtable
    union
    select column2 from yourtable
    union
    select column3 from yourtable
    order by 1;
    Thanks for the solution, vanekl!

    It works wonderfully. I wasn't sure if UNION was supported in 4.0.16 when I was trying it but I got the results as expectedl. So it's supported.

    Btw, what does ORDER BY 1 do?

    cheers

  4. #4
    Join Date
    Oct 2003
    Posts
    63
    Originally posted by pearl2
    Thanks for the solution, vanekl!

    It works wonderfully. I wasn't sure if UNION was supported in 4.0.16 when I was trying it but I got the results as expectedl. So it's supported.

    Btw, what does ORDER BY 1 do?

    cheers
    Hi!

    This set an order by first (1) column in your query colulmns list.

  5. #5
    Join Date
    Nov 2003
    Location
    Sinapore
    Posts
    187
    Originally posted by khibinite
    Hi!

    This set an order by first (1) column in your query colulmns list.
    Cool. Thanks

Posting Permissions

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