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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:51:03+00:00 2026-06-16T05:51:03+00:00

I have three table as follows: documents (id, content) words (id, word) word_document (word_id,

  • 0

I have three table as follows:

documents (id, content) 
words (id, word) 
word_document (word_id, document_id, count)

Words table have all the words occurred in all documents and word_document relate a word to a document and the count of that word in that document.

I want to write a query to search for two words and returns only the documents which have both word ordered by the sum of the count of both words in documents.

For example

DocA: green apple is not blue
DocB: blue apple is blue
DocC: red apple is red

now a search for apple and blue returns:

DocA, 3
DocB, 2

becaus:

DocA contains both words and 3 of them
DocB contains both words and 2 of them
DocC only contains one word

I used intersect successfully but it doesn’t return the count sum and no order.

  • 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-16T05:51:04+00:00Added an answer on June 16, 2026 at 5:51 am

    For those who want this, this only works:

    select wd.document_id, (wd.count + d.count) as tcount from word_document as wd
    join words as w on w.id = wd.word_id
    join
    (select document_id, count from word_document 
    join words on words.id = word_document.word_id
    where words.word = "apple") d on d.document_id=wd.document_id
    where w.word = "blue" order by tcount desc
    

    You can create temp table from the inner query and execute outer on that. It can be done recursively for more words.

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

Sidebar

Related Questions

Ok I am really stuck. I have three tables as follows: table contracts contract_id
i have three tables like follows: this one table : m_application_resources resourceid resource_name menu_group_id
I have three tables which I want to query in MySQ. As follows: **Table:
I have three table views inside a view controller (going to show/hide table views
I have three table I need to query table 1,2 and 3 and select
I have three separate table variables in my Function, 1 of them is not
I have three mysql table from same database Db1. Three tables have following columns.
I have a simple three table reference. It looks plain enough. The associations there
Say I have three tables: Fruit (Table 1) ------ Apple Orange Pear Banana Produce
I have three tables of data: table: cars [10,000 rows] table: planes [2,000 rows]

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.