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 > Find string occurrences

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-18-09, 18:19
trogster trogster is offline
Registered User
 
Join Date: Nov 2009
Posts: 3
Find string occurrences

Hi, I need to do something with sql and I am not quite sure how to do it.

I have a variable string (urls), and I need to check if that string contains any of the keywords that are stored in a table.

For example, I have a table with the entries "keywordX1", "keywordX2", "keywordX3", etc.
Then I have a string such as "http://www.domainwithkeywordX2.com/path/?param=value

How can I quickly find if the url string contains (and which ones) keywords from the table using a sql query? (or any other fast method)

I can't select all the keywords and loop that because in the future the keywords list will be huge, and I need speed.

Thanks.
Reply With Quote
  #2 (permalink)  
Old 11-18-09, 22:24
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
is there a table involved here?

usually SQL is written against tables, but the only table you mentioned is an unnamed table with a column called "entries" which has keywords in it

please do a SHOW CREATE TABLE for each table involved here
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 11-18-09, 23:09
trogster trogster is offline
Registered User
 
Join Date: Nov 2009
Posts: 3
I currently have a table named targets with the columns ID int(11) (primary auto_increment), and keyword varchar(255).

I want to do a sql query and check if my string var (ex. google.com/?q=qwerty) contains any of the keywords in the targets.keyword table.
Reply With Quote
  #4 (permalink)  
Old 11-18-09, 23:20
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
Code:
SELECT DISTINCT 'yes'
  FROM targets
 WHERE 'google.com/?q=qwerty'
       LIKE CONCAT('%',keyword,'%')
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 11-19-09, 01:39
trogster trogster is offline
Registered User
 
Join Date: Nov 2009
Posts: 3
Quote:
Originally Posted by r937 View Post
Code:
SELECT DISTINCT 'yes'
  FROM targets
 WHERE 'google.com/?q=qwerty'
       LIKE CONCAT('%',keyword,'%')
Dude!
Thank you very much, it's 3.38am and I couldn't sleep thinking about how to do this, you saved me.
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