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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T00:42:18+00:00 2026-06-11T00:42:18+00:00

I hope the title somehow makes sense. I’ve got 3 tables in DB. First

  • 0

I hope the title somehow makes sense.

I’ve got 3 tables in DB. First one holds product_variant records, second one holds the label records and the third one is the ref table in between.

  • product_variant: (id, productId, serviceProviderId).
  • label: (id,label).
  • product_variant_label_ref: (label_id,variant_id).

Input parameters for my query are: productType, serviceProviderId and set of labels and
my aim is to select rows in product_variant table based on the input parameters.

This is my query in hibernate xml file:

 SELECT v.*
 FROM product_variant v
     INNER JOIN product_variant_label_ref r ON v.id = r.variant_id
     INNER JOIN product_product p ON p.productType = :productType
     INNER JOIN product_label l ON l.id = r.label_id
     WHERE v.product_id = p.id
        AND v.serviceprovider_id = :serviceProviderId
        AND l.label in (:labels)

Problem is that with IN operator I am getting disjunctive OR selection and I want AND in between. If I specify different labels as an input, I want only those product_variant rows which have a relation to all of them through ref table. If one of the input labels doesn’t belong to any product_variant, query should not return anything. Could anyone help me to change my query?

  • 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-11T00:42:19+00:00Added an answer on June 11, 2026 at 12:42 am

    You need to count the rows returned for each product, and match it to the number of items in your labels parameter

    If you have, for example, 3 labels in your labels parameter…

     SELECT v.id
     FROM product_variant v 
         INNER JOIN product_variant_label_ref r ON v.id = r.variant_id 
         INNER JOIN product_product p ON p.productType = :productType 
         INNER JOIN product_label l ON l.id = r.label_id 
         WHERE v.product_id = p.id 
            AND v.serviceprovider_id = :serviceProviderId 
            AND l.label in (:labels) 
     GROUP BY v.id
     HAVING COUNT(DISTINCT l.id) = 3 -- ie: Length of labels
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok my first post and i hope the title makes sense. I have an
I hope the title makes sense. I have a set of items that I
I hope that title makes sense.... Basically I created PHP script to take data
ok, I hope the title of this question makes sense. In my app I
I hope the title of this question makes sense. What I want to know
I hope this title makes sense - I need case-insensitive regex matching on BlackBerry
I hope my title makes sense, but here is what I a trying to
I hope the title makes at least some sense. I have the situation as
I'm not sure if the title makes sense, but I hope you can understand
I hope my title makes sense. I have an iPhone app uses the standard

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.