Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3480878
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T10:23:38+00:00 2026-05-18T10:23:38+00:00

We have three tables to hold our products and keywords: Product {int ID, string

  • 0

We have three tables to hold our products and keywords:

Product {int ID, string name, ...}
ProductKeyword {int productID, int keywordID}
Keyword {int ID, string keyword}

This SQL code returns the most relevant products to the least relevant products having keywords like the users search criteria. searchWordTable is a table of search words. @keywordCount is a count of the search words. This returns all the products having one or more keywords, ordered by the quantity of keywords found for each product.

select productid, productname, count(*) * 1 / @keywordCount as percentRelevant
from (select keyword, productid, productname
      from   product
             join productkeyword on ... 
             join keyword on ...
             join searchWordTable on searchwordtable.keyword like 
                  '%' + keyword.keyword + '%') K -- like join aweful
group by productid, productname
order by percentRelevant desc -- Most relevant first

The problem is this is a sequential search comparing every keyword we have. It’s not bad, but searches can take a minute with a million records.

How could I rewrite the query to not use like, hopefully use an indexed search, and get similar results? They use like to get partial matches, e.g., ‘bone’ in ‘boneless’.

Links to better SQL algorithms would surely be appreciated.

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T10:23:39+00:00Added an answer on May 18, 2026 at 10:23 am

    Like is killing you, especially with that leading wildcard which completely removes any indexes the columns may have.

    You should look into using SQL Server’s full-text indexing. contains will probably be much faster and is far more powerful for partial matches of the nature you appear to be doing.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have three tables that hold items like: Products: ID NAME CATEGORY STOCK 1
Here's the setup: I have several tables that hold information for data objects which
I have a DB model that uses several tables to hold business logic data;
I have three tables (people, clients_people, clients) that would be joined using SELECT *
I am new to SQL, and have two tables that hold data(I am using
I have three tables that I need get information from, 1 table has the
I'm having trouble selecting a subset of data with doctrine. I have 3 tables
I have a bag whose structure looks like this: <bag name=foo fetch=select table=table_of_foos> <key
I have three table.2 data comes from 2 table and insert it into another
I have three types of questions: Vocab (represented by question:answer pairs) Grammar (represented by

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.