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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:51:05+00:00 2026-05-27T05:51:05+00:00

I have a table called words , consisting of three columns word(VARCHAR(16)), doc_id(INT), weight(DOUBLE)

  • 0

I have a table called words, consisting of three columns word(VARCHAR(16)), doc_id(INT), weight(DOUBLE).

Here is what I need to do, I have two queries:

SELECT doc_id, weight FROM words WHERE word = 'bla';

doc_id    weight
------    ------
1         0.14
2         0.61
3         0.32

and

SELECT doc_id, weight FROM words WHERE word = 'blabla';

doc_id    weight
------    ------
2         0.19
3         0.45
4         0.14

I need to get the intersection of the two on doc_id and select the lower weight value as the weight, i.e. I want the results to be:

doc_id    weight
------    ------
2         0.19
3         0.32

Is there a way to do that in a single query? Doing it in the program makes it damn slow!

I also need to get their UNION and select the higher weight value, i.e. I want the results to be:

doc_id    weight
------    ------
1         0.14
2         0.61
3         0.45
4         0.14

Keep in mind that the column word and doc_id are not unique, so one word can be assigned to many docs.

  • 1 1 Answer
  • 3 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-05-27T05:51:06+00:00Added an answer on May 27, 2026 at 5:51 am

    For the intersect part it sounds like you want “the lowest weight for all doc_id where the doc_id has one row for the word ‘bla’ AND one row for the word ‘blabla'”. That can be found by

    (untested)
    select w1.doc_id, least(min(w1.weight), min(w2.weight)) as minweight 
      from words w1, words w2
     where w1.doc_id = w2.doc_id
       and w1.word = 'bla'
       and w2.word = 'blabla'
     group by w1.doc_id;
    

    For the union part what you want is “the highest weight for all doc_id where the doc_id has one row for the word ‘bla’ OR one row for the word ‘blabla'”. That can be found by

    (untested)
    select doc_id, max(weight) as maxWeight
      from words
     where word in ('bla', 'blabla')
     group by doc_id;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table called Follow , with three fields: Id (autoincrement int), UserId
I have a table called sellerparams with a number of columns, one of them
I have a table called 'main_table' with 3 columns : 'player', 'points' and 'drop_date'
I have a table called 'survey_product' with the following structure: id int(11) order_id int(11)
I have a table called keywords. It's simple, two columns - id and keyword.
I have a table called Payroll. Payroll can have many PayStubs. In other words
I have a table A with the following columns: Status varchar StateCode bit OpportunityID
I have a table in my DB called Emplyee and contains these columns :
I have a table with words from a text (the table is called token
I have a table called Visits : ID(PKey,Int) PatiendID(int), DoctorID(int), ExpectedDate(date), ActualDate(date), How can

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.