If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Sort words from different columns...

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-07-04, 07:25
pearl2 pearl2 is offline
Registered User
 
Join Date: Nov 2003
Location: Sinapore
Posts: 187
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
Reply With Quote
  #2 (permalink)  
Old 02-07-04, 08:40
vanekl vanekl is offline
Registered User
 
Join Date: Nov 2003
Posts: 91
select column1 from yourtable
union
select column2 from yourtable
union
select column3 from yourtable
order by 1;
Reply With Quote
  #3 (permalink)  
Old 02-09-04, 03:06
pearl2 pearl2 is offline
Registered User
 
Join Date: Nov 2003
Location: Sinapore
Posts: 187
Quote:
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
Reply With Quote
  #4 (permalink)  
Old 02-09-04, 04:47
khibinite khibinite is offline
Registered User
 
Join Date: Oct 2003
Posts: 63
Quote:
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.
Reply With Quote
  #5 (permalink)  
Old 02-09-04, 08:35
pearl2 pearl2 is offline
Registered User
 
Join Date: Nov 2003
Location: Sinapore
Posts: 187
Quote:
Originally posted by khibinite
Hi!

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

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On