Results 1 to 6 of 6

Thread: Best way to query

  1. #1
    Join Date
    Mar 2004
    Posts
    4

    Best way to query

    I have a database that contains a large group of phrases. It has a very simple structure, just an auto ID field and a phrase.

    What I want to do is to check words in a sentence to see if they match an existing phrase. I have thought of a way to do this, but was wondering if anyone had a better idea.

    Example sentence: "This is a test"

    Method - Do a LIKE on every word in the sentence:
    - Select * from tblPhrases where phrase Like "This %"
    - Select * from tblPhrases where phrase Like "is %"
    - Select * from tblPhrases where phrase Like "a %"
    - Select * from tblPhrases where phrase Like "test %"

    Any help is appreciated.

  2. #2
    Join Date
    Mar 2003
    Posts
    468
    depends on your requirements for a match.

    in your SQL, the phrase must begin with the words given. If you want to check for existance anywhere in the phrase you need something like :
    Select * from tblPhrases where phrase Like "%This %"

    also, it is more efficient to check for likeness of all words at the same time and not individual select statements:
    Select * from tblPhrases where phrase Like "%This %"
    and phrase Like "%is %"
    and phrase Like "%a %"
    and phrase Like "%test %"

  3. #3
    Join Date
    Mar 2004
    Posts
    4
    The phrase needs to be exactly the same as what is contained in the sentence (ignoring case).

    Is there a way to do this other than using the LIKE command? My fear is that even with an index on the phrase, it will still be fairly slow.

    Thanks.

  4. #4
    Join Date
    Mar 2003
    Posts
    468
    if you need it to be exactly like the statement then your sql is:
    Select * from tblPhrases where phrase = "This is a test"

    an index will speed this up but may be a bit on the large side depending on the number of rows in the table.

  5. #5
    Join Date
    Mar 2004
    Posts
    4
    So to pull the phrase or phrases from the sentence I would need to do either the LIKE, or something like this:

    - select * from tblPhrases where phrase="this is a test" or phrase="this is a" or phrase="this is" or phrase="this" or ...

    Is this correct?

  6. #6
    Join Date
    Mar 2003
    Posts
    468
    yup,
    give it a try and make sure that is what you need.

Posting Permissions

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