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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:41:05+00:00 2026-05-31T13:41:05+00:00

I have three tables: items: id name 4 Item Blue, L 2 Item Blue,

  • 0

I have three tables:

items:

id   name
4   Item Blue, L
2   Item Blue, S
6   Item Green
8   Item L
9   Item Red, Blue, Green, S, M, L
5   Item Red, L
3   Item Red, M
1   Item Red, S
7   Item S

options:

id   group   name
1   1   red
2   1   blue
3   1   green
4   2   s
5   2   m
6   2   l

items_has_options:

item_id   options_id
1   1
1   4
2   2
2   4
3   1
3   5
4   2
4   6
5   1
5   6
6   3
7   4
8   6
9   1
9   2
9   3
9   4
9   5
9   6

How can i select items which have options: (red or blue or green) and (s)? I need to choose items which have some options from different groups. Options may have many groups, not only two. Result must be:

2   Item Blue, S
9   Item Red, Blue, Green, S, M, L
1   Item Red, S
  • 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-31T13:41:07+00:00Added an answer on May 31, 2026 at 1:41 pm

    Not sure this will work but it might get you started..

    SELECT DISTINCT i.id, i.name FROM items i
    INNER JOIN items_has_options ihs1 ON
        i.id = ihs1.item_id
    INNER JOIN items_has_options ihs2 ON
        i.id = ihs2.item_id
    INNER JOIN options o1 ON
        ihs1.options = o1.id AND (o1.name = "red" OR o1.name = "blue" OR o1.name="green")
    INNER JOIN options o2 ON
        ihs2.options = o2.id AND o2.name = "s"
    

    The idea is that you join with the options table twice, once for color and once for size.
    You need the distinct since you will get duplicate rows from o1…

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

Sidebar

Related Questions

I have three tables filters (id, name) items(item_id, name) items_filters(item_id, filter_id, value_id) values(id, filter_id,
I have three mysql tables items =========== id title items_in_categories ============================ id item_id category_id
This has been driving me mad. I have three tables: items ID name type
I have the following tables: users (id,name) items (id,title) users_items (user_id,item_id) users and items
Let's say you have three tables named Item, Event, and Seat, constructed as such:
I'm having some trouble using constraints correctly. I have three tables, 'item', 'store' and
i have this three tables. Table: Item Columns: ItemID, Title, Content, NoChange (Date) Table:
I have three tables: | items -------- id quantity size_attribute_value_id color_attribute_value_id type_attribute_value_id | attribute_values
I have three models, basically: class Vendor has_many :items end class Item has_many :sale_items
I have two tables, meetings_table and items_table . items_table has three columns: id item

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.