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 8603713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:23:17+00:00 2026-06-12T02:23:17+00:00

I have a table structure which is basically: Items ID: INT(10) Title: CHAR(255) ItemsWords

  • 0

I have a table structure which is basically:

Items
ID: INT(10)
Title: CHAR(255)

ItemsWords
ID: INT(10)
ItemID: INT(10)
Word: CHAR(50)

For each ‘Item’ record, there are multiple records in the ‘ItemsWords’ table.

I can find all items using this which contain a single word like this:

SELECT * FROM Items i, ItemsWords w WHERE w.ItemID=i.ID AND w.Word='WORD_TO_FIND'

I can find all items using this which contain any of a number of words like this:

SELECT * FROM Items i, ItemsWords w 
WHERE w.ItemID=i.ID 
AND (w.Word='WORD_TO_FIND' OR w.Word='ANOTHER_WORD_TO_FIND')

But I also want to be able to use the same table structure to find only the ‘Items’ which contain ALL of any number of search words.

I know I could use FullText by the Items table has over 100,000 records and the ItemWords table many time more than that, so have set up the structure this way to make these searches very quick and with minimum server impact. The one word or ANY word searches above are indeed super speedy.

Thank you!

  • 1 1 Answer
  • 0 Views
  • 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-06-12T02:23:18+00:00Added an answer on June 12, 2026 at 2:23 am
    select Items.id, Items.Title
    from Items
       inner join ItemsWords   
       on Items.ID = ItemsWords.ItemID
    where ItemsWords.Word in ('WORD_TO_FIND','ANOTHER_WORD_TO_FIND') 
    group by Items.id, Items.Title
    having count(distinct ItemsWords.id) =2
    

    The number in the final line is the number of words in the list of words you are searching for (ie: 2 in this instance.

    Note how the tables are joined using the inner join syntax, rather than a where clause

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

Sidebar

Related Questions

I have an SQL table with basically the following structure: PK (int, primary key),
I have a table which is basically a tree structure with a column parent_id
I have the following table structure inside a view which gets displayed in the
I have two table masterTbl and detailTbl which structure is given below... --PRIMARY TABLE
I have the following table structure, which is imported into an Entity Framework project:
I have the following html structure (which is generated and I can't change): <table
I have a table called Billing , which is basically a receipt (for different
I have a database which has multiple nested associates. Basically, the structure is as
I have xib in which i have couple of views, but basically structure looks
I have two tables with the following (simplified) structures: table "Factors" which holds data

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.