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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:19:49+00:00 2026-06-15T17:19:49+00:00

I have a table containing perfectly defined items and a second table with potentially

  • 0

I have a table containing perfectly defined items and a second table with potentially vague/greedy orders as NULL would require all available values for this parameter.

items
+-----------------------+
| item_id | color | size |
|---------+-------+------|
|    1    |  blue |    8 |
|    2    |   red |    6 |
|    3    | green |    7 |
|    4    | black |    6 |
+------------------------+

orders
+-------------------------+
| order_id | color | size |
|----------+-------+------|
|     1    |   red |    6 |
|     2    | green |    8 |
|     3    |  NULL |    6 |
|     4    |  blue | NULL |
|     5    |  NULL | NULL |
+-------------------------+

Is there an efficient way to generate a complete list of items needed to fill all orders?

+--------------------+
| order_id | item_id |
|----------+---------|
|     1    |    2    |
|     3    |    2    |
|     3    |    4    |
|     4    |    1    |
|     5    |    1    |
|     5    |    2    |
|     5    |    3    |
|     5    |    4    |
+--------------------+

It seems to me like an INNER JOIN should be able to do this, but something like this obviously doesn’t consider the possibility of NULL values as greedy wildcards in the orders table:

SELECT order_id, item_id
FROM orders
INNER JOIN items ON orders.color = items.color AND orders.size = items.size

Any ideas?

  • 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-15T17:19:50+00:00Added an answer on June 15, 2026 at 5:19 pm

    Try the following:

    SELECT order_id, item_id
    FROM orders
    INNER JOIN items ON (orders.color IS NULL OR orders.color = items.color)
        AND (orders.size IS NULL OR orders.size = items.size)
    

    Let me know if that helps, or if I misunderstood the question.

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

Sidebar

Related Questions

I have a Table containing some information that I need. All these rows also
I have a table containing transaction information on items. The possible transactions are purchase
I have a table containing hundreds of columns many of which are null, and
I have a table containing a series of names, events and dates. I've created
I have a table containing the results of games played. I have another table
I have a table containing data about some users. Many of them use our
I have a table containing reports and the date/time they were created. I'd like
I have a table containing view/click records. The time is stored in a unix
I have a table containing cells with phone numbers. How can I allow the
I have a table containing 2 date fields and an identifier (id, fromdate and

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.