Home > Archive > Microsoft SQL Server Desktop Engine > August 2005 > How to find records that contain all words?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author How to find records that contain all words?
Terry Olsen

2005-08-06, 8:23 pm

I need to return records that contain all the words a user enters. For
example, I have the Bible in an SQL database. I want to be able to return
the verses that contain all of the following words: 'for', 'god', 'so'. If
I use the following:

select Book,Chap,Verse from Bible where
Verse like '%for%' and
Verse like '%god%' and
Verse like '%so%'

I get returns with words like 'forgotten', 'some', etc. So then I tried
using spaces...

select Book,Chap,Verse from Bible where
(Verse like '% for %' or Verse like '% for%' or Verse like '%for %') and
(Verse like '% god %' or Verse like '% god%' or Verse like '%god %') and
(Verse like '% so %' or Verse like '% so%' or Verse like '%so %')

But I get the same results. It seems that the spaces in the select statment
are being ignored.

Can anyone help?

Thanks.


Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com