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

The Archive Base Latest Questions

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

I have 4 tables; articles machines features required features the problem is that articles

  • 0

I have 4 tables;

  • articles
  • machines
  • features
  • required features

the problem is that articles can be produced on machines but only on the machines that have the features that are required by the articles.
a product can require 0 or more features and a machine can have 0 or more features

I want to create a query that shows a complet overview of valid article-machine combinations.
the question is: How can I do that?

Below is an example data set for MySQL. it should result in the following query result:

"car";"virtual machine"
"boat";"virtual machine"
"boat";"lean machine"

here’s the dataset:

CREATE TABLE IF NOT EXISTS `articles` (
  `name` text NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

INSERT INTO `articles` (`name`) VALUES
('car'),
('boat');

CREATE TABLE IF NOT EXISTS `features` (
  `machine` text NOT NULL,
  `feature_name` text NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

INSERT INTO `features` (`machine`, `feature_name`) VALUES
('lean machine', 'punch'),
('virtual machine', 'punch'),
('virtual machine', 'drill');

CREATE TABLE IF NOT EXISTS `machines` (
  `name` text NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

INSERT INTO `machines` (`name`) VALUES
('lean machine'),
('virtual machine');

CREATE TABLE IF NOT EXISTS `required_features` (
  `article` text NOT NULL,
  `feature` text NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

INSERT INTO `required_features` (`article`, `feature`) VALUES
('car', 'drill'),
('boat', 'punch');
  • 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-23T13:31:40+00:00Added an answer on May 23, 2026 at 1:31 pm

    With the data you provide, the solution is just a few joins – but I’m assuming that it’s possible for an article to require more than one feature, and for a machine to have one of those features, but not all the features required.

    In this case, you would need to also make sure that a machine that has a matching feature of an article also doesn’t lack any other features required by the article. I don’t think a left join would do the job because it would then return the machine for the matching feature, and the null for the non-matching feature… whereas it shouldn’t return the machine at all in this case.

    SELECT DISTINCT
        a.name,
        m.name
    FROM
        articles a INNER JOIN
        required_features rf ON rf.article = a.name INNER JOIN
        features f ON f.feature_name = rf.feature INNER JOIN
        machines m 
            ON m.name = f.machine
            -- Make sure that there is no feature required that isn't provided by the machine.
            AND NOT EXISTS (
                SELECT 1
                FROM 
                    machines m2 INNER JOIN
                    features f2 ON f2.machine = m2.name LEFT JOIN
                    required_features rf2 ON rf2.feature = f2.feature_name
                WHERE 
                    m2.name = m.name AND
                    rf2.feature IS NULL
                    AND rf2.article = a.name
            )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have three tables like that: Articles IdArticle Title Content Tags IdTag TagName ContentTag
I have a 2 tables that I wish to update articles and articles_entities articles
I have two tables: articles and articletags articles: id, author, date_time, article_text articletags: id,
In my database I have tables that define types for example Table: Publication Types
When I have tables in my database that have PK/FK relationships (int) and when
I have several tables whose only unique data is a uniqueidentifier (a Guid) column.
I have 3 tables: articles, tags and article_tag (the one which connects them). I'd
If all tables I want to delete from have the column gamer_id can i
I have 2 tables: Articles: ID INTEGER ... Article_versions: article INTEGER lang ENUM time
I am working on a project using SqlSiteMapProvider. I have two tables Articles 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.