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 > Search on keywords

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-22-06, 02:53
rexselin rexselin is offline
Registered User
 
Join Date: Aug 2003
Location: India
Posts: 109
Search on keywords

Hi,

I have a table which stores keywords as a comma separated list. The records are like

1) Ad Name | car rentals, car advertising
2) Ad Name | car, bmw, bike


I would want to search for 'car' and would like to have only the second record listed and not the first record. But our usual query where keyword like '%car%' wouldn't work here. Is it possible to split these keywords in the query itself and then make it work?

I hope I was clear in explaining my need.
Reply With Quote
  #2 (permalink)  
Old 07-22-06, 07:19
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
you should not have a table which stores keywords in a comma-separated list, because this violates first normal form

you will find that the queries will be much easier to construct if you have a table which stores one row per keyword
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 07-22-06, 13:22
rexselin rexselin is offline
Registered User
 
Join Date: Aug 2003
Location: India
Posts: 109
No, that was a question asked to me by a fellow friend and his job was to import data from a existing db to a new db. ( couldn't argue with them )

Anyway, I came up with a query.. Not sure whether it would work always..

select * from ads where (ad_words like '^car,' or ad_words regexp ',car,' or ad_words regexp ',car$' or ad_word regexp 'car')

seemed to work with the present db.
Reply With Quote
  #4 (permalink)  
Old 07-22-06, 17:33
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
if it works, i'll take your word for it, but it will never scale, because it is forced to do a table scan

the more rows your table has, the slower the query gets

good luck
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
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