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 > WHERE 4 of the 10 keywords available in records

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-24-08, 17:10
gilgalbiblewhee gilgalbiblewhee is offline
Registered User
 
Join Date: Jul 2004
Posts: 494
WHERE 4 of the 10 keywords available in records

Is it possible to have several keywords in the search separated with an OR but only to show the records where there are ...let's say 4 of the 10 keywords available?
__________________
Compare bible texts (and other tools):
TheWheelofGod
Reply With Quote
  #2 (permalink)  
Old 06-24-08, 17:31
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
yes, it is

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 06-24-08, 18:03
gilgalbiblewhee gilgalbiblewhee is offline
Registered User
 
Join Date: Jul 2004
Posts: 494
Ok ... how?
__________________
Compare bible texts (and other tools):
TheWheelofGod
Reply With Quote
  #4 (permalink)  
Old 06-24-08, 18:21
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
with a GROUP BY and HAVING



i will give more info, if you will give more info

for starters, what is the primary key of the table, please?

and how are the keywords related to the main table?
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 06-24-08, 23:15
gilgalbiblewhee gilgalbiblewhee is offline
Registered User
 
Join Date: Jul 2004
Posts: 494
Here's an example:
Quote:
SELECT * FROM bible WHERE 1=1 AND text_data LIKE '%there%' OR text_data LIKE '%house%' OR text_data LIKE '%daughter%' OR text_data LIKE '%woman%' OR text_data LIKE '%conceived%' OR text_data LIKE '%goodly%' OR text_data LIKE '%child%' OR text_data LIKE '%three%' OR text_data LIKE '%months%' LIMIT 0, 10
The primary key is ID. The keywords are found in the text_area column.
__________________
Compare bible texts (and other tools):
TheWheelofGod
Reply With Quote
  #6 (permalink)  
Old 06-24-08, 23:27
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
Code:
SELECT * 
  FROM bible 
 WHERE 1=1 
   AND CASE WHEN text_data LIKE '%there%' 
            THEN 1 ELSE 0 END
     + CASE WHEN text_data LIKE '%house%' 
            THEN 1 ELSE 0 END
     + CASE WHEN text_data LIKE '%daughter%' 
            THEN 1 ELSE 0 END
      > 1
this example shows how to test to see if at least 2 of the 3 conditions have been met
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #7 (permalink)  
Old 08-22-08, 19:57
gilgalbiblewhee gilgalbiblewhee is offline
Registered User
 
Join Date: Jul 2004
Posts: 494
Quote:
Originally Posted by r937
Code:
SELECT * 
  FROM bible 
 WHERE 1=1 
   AND CASE WHEN text_data LIKE '%there%' 
            THEN 1 ELSE 0 END
     + CASE WHEN text_data LIKE '%house%' 
            THEN 1 ELSE 0 END
     + CASE WHEN text_data LIKE '%daughter%' 
            THEN 1 ELSE 0 END
      > 1
this example shows how to test to see if at least 2 of the 3 conditions have been met
how can I add another field outside of the CASES?
__________________
Compare bible texts (and other tools):
TheWheelofGod
Reply With Quote
  #8 (permalink)  
Old 08-22-08, 19:58
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
outside of?
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #9 (permalink)  
Old 08-22-08, 20:07
gilgalbiblewhee gilgalbiblewhee is offline
Registered User
 
Join Date: Jul 2004
Posts: 494
Quote:
Originally Posted by r937
outside of?
What I mean is,
If I have this:
Code:
SELECT *
  FROM (
       SELECT bible.* 
            , CASE WHEN text_data LIKE '%there%' 
                   THEN 1 ELSE 0 END
            + CASE WHEN text_data LIKE '%house%' 
                   THEN 1 ELSE 0 END
            + CASE WHEN text_data LIKE '%daughter%' 
                   THEN 1 ELSE 0 END
              AS relevance      
         FROM bible
        WHERE text_data LIKE '%there%'
           OR text_data LIKE '%house%'
           OR text_data LIKE '%daughter%'
      ) AS d 
 WHERE relevance > 4
ORDER
    BY relevance
Where am I going to fit "AND book_spoke = ' ' OR chapter_spoke=' ' OR verse_spoke = ' '"
__________________
Compare bible texts (and other tools):
TheWheelofGod
Reply With Quote
  #10 (permalink)  
Old 08-23-08, 01:03
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
Code:
SELECT *
  FROM (
       SELECT bible.* 
            , CASE WHEN text_data LIKE '%there%' 
                   THEN 1 ELSE 0 END
            + CASE WHEN text_data LIKE '%house%' 
                   THEN 1 ELSE 0 END
            + CASE WHEN text_data LIKE '%daughter%' 
                   THEN 1 ELSE 0 END
              AS relevance      
         FROM bible
        WHERE (
              text_data LIKE '%there%'
           OR text_data LIKE '%house%'
           OR text_data LIKE '%daughter%'
              )
          AND (
              book_spoke = ' ' 
           OR chapter_spoke = ' ' 
           OR verse_spoke = ' ' 
              )
      ) AS d 
 WHERE relevance > 4
ORDER
    BY relevance
__________________
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