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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T17:51:24+00:00 2026-05-13T17:51:24+00:00

This query appears to work well: — Every supplier that produces some red or

  • 0

This query appears to work well:

-- Every supplier that produces some red or green part
SELECT Suppliers.sid
FROM Suppliers, Catalog, Parts
WHERE Suppliers.sid = Catalog.sid 
    AND Catalog.pid = Parts.pid
    AND (Parts.color = "red" OR Parts.color = "green");

To check it, I’d like to look at every SID that will not be returned by this query, to make sure that they do not produce green or red parts. How can I do this?

This doesn’t seem to be working:

SELECT Parts.color
FROM Suppliers, Catalog, Parts
WHERE Suppliers.sid NOT IN (    
    SELECT Suppliers.sid, Parts.color
    FROM Suppliers, Catalog, Parts
    WHERE Suppliers.sid = Catalog.sid 
        AND Catalog.pid = Parts.pid
        AND (Parts.color = "red" OR Parts.color = "green")
    );

MySQL Error:

Error 1241 (21000): Operand should
contain 1 column(s)

What is the right way to go about this?

This is the SQL used to create the tables I’m working with:

SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL';

CREATE SCHEMA IF NOT EXISTS `mydb` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci ;
USE `mydb`;

-- -----------------------------------------------------
-- Table `mydb`.`Suppliers`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `mydb`.`Suppliers` (
  `sid` INT NOT NULL ,
  `sname` VARCHAR(45) NULL ,
  `address` VARCHAR(45) NULL ,
  PRIMARY KEY (`sid`) )
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `mydb`.`Parts`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `mydb`.`Parts` (
  `pid` INT NOT NULL ,
  `pname` VARCHAR(45) NULL ,
  `color` VARCHAR(45) NULL ,
  PRIMARY KEY (`pid`) )
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `mydb`.`Catalog`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `mydb`.`Catalog` (
  `cost` INT NULL ,
  `pid` INT NOT NULL ,
  `sid` INT NOT NULL ,
  PRIMARY KEY (`pid`, `sid`) ,
  INDEX `fk_Catalog_Parts1` (`pid` ASC) ,
  INDEX `fk_Catalog_Suppliers1` (`sid` ASC) ,
  CONSTRAINT `fk_Catalog_Parts1`
    FOREIGN KEY (`pid` )
    REFERENCES `mydb`.`Parts` (`pid` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_Catalog_Suppliers1`
    FOREIGN KEY (`sid` )
    REFERENCES `mydb`.`Suppliers` (`sid` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;



SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
  • 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-13T17:51:24+00:00Added an answer on May 13, 2026 at 5:51 pm

    NOt completely knowing what you are getting at I see a couple of things wrong. First remove the second column inthe subquery, it is unnecessary:

    SELECT Parts.color 
    FROM Suppliers, Catalog, Parts 
    WHERE Suppliers.sid NOT IN (     
        SELECT Suppliers.sid    FROM Suppliers, Catalog, Parts 
        WHERE Suppliers.sid = Catalog.sid  
            AND Catalog.pid = Parts.pid 
            AND (Parts.color = "red" OR Parts.color = "green") 
        ); 
    

    Finally you apear to have a cross join which I supect you don’t want. This is a classic example of why you should not use implicit joins. See if this might work better:

    SELECT Parts.color 
    FROM Suppliers 
    JOIN Catalog  on Suppliers.sid = Catalog.sid  
    JOIN  Parts on Catalog.pid = Parts.pid 
    WHERE Suppliers.sid NOT IN (     
        SELECT Suppliers.sid
        FROM  Suppliers 
        JOIN Catalog  on Suppliers.sid = Catalog.sid  
        JOIN  Parts on Catalog.pid = Parts.pid 
           WHERE (Parts.color = "red" OR Parts.color = "green") 
        ); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This query selects all the unique visitor sessions in a certain date range: select
This query works: item = db.GqlQuery(SELECT * FROM Item WHERE CSIN = 13)[0] although
This query that I have is returning therapists whose 'therapistTable.activated' is equal to false
In this query: SELECT COUNT(*) AS UserCount, Company.* FROM Company LEFT JOIN User ON
Take this query: SELECT * FROM MyTable WHERE MyColumn = 'SomeValue' ORDER BY SomeFakeQualifier.MyColumn
Why this query doesn’t working: SELECT name FROM ( SELECT name FROM table1 UNION
This is a two part question. A dumb technical query and a broader query
Can someone please explain to me what is going on with this query? select
I have a MySQL query like this: SELECT xid, count(yid) AS tot FROM x_y_map
I'm running this query SELECT country, countries.code, countries.lat, countries.lng, countries.zoom, worldip.start, worldip.end FROM countries,

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.