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

  • Home
  • SEARCH
  • 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 7069441
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:26:46+00:00 2026-05-28T05:26:46+00:00

I’m having difficulties grasping how to do this. I am making a product options

  • 0

I’m having difficulties grasping how to do this. I am making a “product options” table, which will contain all possible variants of a product based on the attributes attached. So if red, small, blue and large are attached to the product the options are small red, large red, small blue and large blue. For this I presume I have to reverse the one-to-many, but I am struggle with how.

Right now I am trying to retrieve an option that matches the specified values. So for example, if I search for red and small, it will give me the “small red” option. This is what I have been trying based on a previous question I asked:

SELECT o.name
FROM shop_products_options o
WHERE o.id IN (
    SELECT v.option_id
    FROM shop_products_options_values v
    WHERE v.product_id = 1 AND v.value_id IN(4,7)
    GROUP BY v.option_id
)

This returns all options that match either 4 or 7 (the IDs for the small and red values) just once. How can I get it to return just the option_id’s that are an exact match to both 4 and 7?

I could do it using a comma-delimited list but I’d rather see if there is a normalized way of doing it first that will work.
Thanks for any advice 🙂

  • 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-05-28T05:26:46+00:00Added an answer on May 28, 2026 at 5:26 am

    Unless I’ve misunderstood, try something like this. Search for all option_id’s for 4, and then for 7 and use INTERSECT to only return the values which exist for both.

    SELECT o.name
    FROM shop_products_options o
    WHERE o.id IN (
    SELECT v.option_id
    FROM shop_products_options_values v
    WHERE v.product_id = 1 AND v.value_id = 4
    GROUP BY v.option_id
    
    INTERSECT
    
    SELECT v.option_id
    FROM shop_products_options_values v
    WHERE v.product_id = 1 AND v.value_id = 7
    GROUP BY v.option_id
    )
    

    Note – INTERSECT isn’t supported in MySQL, so an alternative would be to use multiple subqueries

    SELECT o.name
    FROM shop_products_options o
    WHERE o.id IN (
    SELECT v.option_id
    FROM shop_products_options_values v
    WHERE v.product_id = 1 AND v.value_id = 4
    GROUP BY v.option_id
    )
    
    AND o.id IN (
    SELECT v.option_id
    FROM shop_products_options_values v
    WHERE v.product_id = 1 AND v.value_id = 7
    GROUP BY v.option_id
    )
    

    The GROUP BY part may not be necessary

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a text area in my form which accepts all possible characters from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
this is what i have right now Drawing an RSS feed into the php,
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

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.