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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:21:32+00:00 2026-06-18T09:21:32+00:00

I have a database that contains products, beds to be specific. The details of

  • 0

I have a database that contains products, beds to be specific. The details of each bed is stored in a products table, but then I have a separate table, product_bedding_sizes that holds records for each size a bed can in. So one bed may have five entries in this table (it’s a one-to-many relationship).

That bit is done. However, on the public website, visitors can search products and restrict their search to a particular bed size. So my question is, how can I take an array of sizes and select all bed products that may have one or more entries for the specified sizes?

A simplified schema:

CREATE TABLE `products` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(255) NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `name` (`name`)
) ENGINE=InnoDB;

CREATE TABLE `product_bedding_sizes` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `product_id` int(10) unsigned NOT NULL,
  `size` int(10) unsigned NOT NULL,
  PRIMARY KEY (`id`),
  KEY `product_id` (`product_id`)
) ENGINE=InnoDB;

ALTER TABLE `product_bedding_sizes`
  ADD CONSTRAINT `product_bedding_sizes_ibfk_1`
    FOREIGN KEY (`product_id`)
    REFERENCES `products` (`id`)
    ON DELETE CASCADE
    ON UPDATE CASCADE;

If the user selects say, 90cm and 120cm, the plain English explanation of the query would be:

Select all from the products table where it may have a sizein the product_bedding_sizes table that’s 90cm or 120cm.

  • 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-18T09:21:33+00:00Added an answer on June 18, 2026 at 9:21 am

    I take your requirement to be that a row should be returned if the product has a size of 90 OR if it has a size of 120, or both. (The query would be slightly different to return rows where the product has both size of 90 AND a size of 120.)

    Any of these queries return the specified result:

    SELECT p.id
         , p.name
      FROM products p
      JOIN product_bedding_sizes s
        ON s.product_id = p.id
       AND s.size IN (90,120)
     GROUP
        BY p.id
         , p.name
    

    –or–

    SELECT p.id
         , p.name
      FROM products p
      JOIN ( SELECT s.product_id
               FROM product_bedding_sizes s
              WHERE s.size IN (90,120)
              GROUP BY s.product_id
           ) t
        ON t.product_id = p.id
     ORDER
        BY p.id
         , p.name
    

    — or —

    SELECT p.id
         , p.name
      FROM products p
     WHERE EXISTS
           ( SELECT 1
               FROM product_beddings_sizes s
              WHERE s.product_id = p.id
                AND s.size IN (90,120)
           )
     ORDER
        BY p.id
         , p.name
    

    — or —

    SELECT p.id
         , p.name
      FROM products p 
     WHERE p.id IN
           ( SELECT s.product_id
               FROM product_bedding_sizes s
              WHERE s.size IN (90,120)
           )
     ORDER
        BY p.id
         , p.name
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a database table TravelRequest that contains, amongst other things, the fields SignOffName
I have a productdatabase that contains products, parts and labels for each part based
My database has a products table. This contains a column called layers . That
I have several databases that each have a table called, say, products . One
I have a table in a database that contains a variety of paths to
I have an existing database that contains 4 tables: categories, sub-categories, products, prices. I
I have a products table with a column that contains a space separated list
On my database I have among other tables, products . Products table contains the
Situation: I have a database that contains sales records, each record has a ID
I have a database that contains a history of product sales. For example the

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.