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 > question on using LIKE...

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-09-04, 08:41
pearl2 pearl2 is offline
Registered User
 
Join Date: Nov 2003
Location: Sinapore
Posts: 187
question on using LIKE...

Hi,

I've a similar question to the one I asked at http://www.dbforums.com/t982096.html. Given the following columns and their corresponding entries, how do I select only words beginning with a certain letter?

Code:
column1    column2    column3
cheer        town          greed
occupy      serene       addicted
provide     astute        recoup
able          cool           health
bright        tanned       abort
I was playing with something like the following to select words beginning with the letter 'A' without much luck:
Code:
SELECT column1, column2, column3
FROM words
WHERE ??? LIKE 'A%'
I don't know what to put in place of ???.

Hope someone can enlighten me

TIA
Reply With Quote
  #2 (permalink)  
Old 02-09-04, 10:28
calum433 calum433 is offline
Registered User
 
Join Date: Jan 2004
Location: Aberdeen
Posts: 12
select column1, column2, column3
from words
where column1 like 'A%'
or column2 like 'A%'
or column3 like 'A%'

However, you'd get the following back

occupy serene addicted
etc.

If you only want addicted, astute, able and abort back then
I'd suggest three queries.

select column1
from words
where column1 like 'A%'

select column2
from words
where column2 like 'A%'

etc.
Reply With Quote
  #3 (permalink)  
Old 02-09-04, 10:28
vanekl vanekl is offline
Registered User
 
Join Date: Nov 2003
Posts: 91
select column1 from yourtable where column1 like 'A%'
union
select column2 from yourtable where column2 like 'A%'
union
select column3 from yourtable where column3 like 'A%'
order by 1;
Reply With Quote
  #4 (permalink)  
Old 02-10-04, 08:29
pearl2 pearl2 is offline
Registered User
 
Join Date: Nov 2003
Location: Sinapore
Posts: 187
Quote:
Originally posted by vanekl
select column1 from yourtable where column1 like 'A%'
union
select column2 from yourtable where column2 like 'A%'
union
select column3 from yourtable where column3 like 'A%'
order by 1;
Thanks, vanekl! I'm ashamed I didn't think of trying that...

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