Results 1 to 5 of 5
  1. #1
    Join Date
    Nov 2009
    Posts
    3

    Unanswered: 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.

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    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
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    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.

  4. #4
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Code:
    SELECT DISTINCT 'yes'
      FROM targets
     WHERE 'google.com/?q=qwerty'
           LIKE CONCAT('%',keyword,'%')
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  5. #5
    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.

Posting Permissions

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