Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. SQL Server
  3. Question
SQL Server

What is the minus in sql server?

Asked by Anna Ball Apr 16, 2021 11 views 1 answer
Share

About this question

These are the tables I have created and inserted values into it:

CREATE TABLE Customer (Customer_No INTEGER IDENTITY (1,1) PRIMARY KEY, Customer_Name VARCHAR(30) NOT NULL ) CREATE TABLE DVD (DVD_No INTEGER IDENTITY (1,1) PRIMARY KEY, DVD_Name VARCHAR(30) ) CREATE TABLE DVD_Purchase (DVD_Purchase_No INTEGER IDENTITY (1,1) PRIMARY KEY, DVD_No INTEGER NOT NULL, Customer_No INTEGER NOT NULL ) INSERT INTO Customer (Customer_Name) VALUES('Daman') INSERT INTO Customer (Customer_Name) VALUES('Saif') INSERT INTO Customer (Customer_Name) VALUES('Gurung') INSERT INTO Customer (Customer_Name) VALUES('Upendra') INSERT INTO Customer (Customer_Name) VALUES('Ornob') INSERT INTO DVD (DVD_Name) VALUES('Bleach') INSERT INTO DVD (DVD_Name) VALUES('Gintama') INSERT INTO DVD (DVD_Name) VALUES('Tokyo Ghoul') INSERT INTO DVD (DVD_Name) VALUES('Death Note') INSERT INTO DVD (DVD_Name) VALUES('Rurouni Kenshin') INSERT INTO


DVD_Purchase (DVD_No,Customer_No) VALUES (4,1) INSERT INTO DVD_Purchase (DVD_No,Customer_No) VALUES (1,2) INSERT INTO DVD_Purchase (DVD_No,Customer_No) VALUES (1,3) INSERT INTO DVD_Purchase (DVD_No,Customer_No) VALUES (2,3) INSERT INTO DVD_Purchase (DVD_No,Customer_No) VALUES (3,3) INSERT INTO DVD_Purchase (DVD_No,Customer_No) VALUES (4,3) INSERT INTO DVD_Purchase (DVD_No,Customer_No) VALUES (1,4) INSERT INTO DVD_Purchase (DVD_No,Customer_No) VALUES (2,4) INSERT INTO DVD_Purchase (DVD_No,Customer_No) VALUES (5,1) INSERT INTO DVD_Purchase (DVD_No,Customer_No) VALUES (5,2) INSERT INTO DVD_Purchase (DVD_No,Customer_No) VALUES (5,3) INSERT INTO DVD_Purchase (DVD_No,Customer_No) VALUES (5,4) In order to display



customer names who did not purchase any DVD by using MINUS operator, this is what I have tried: SELECT Customer_Name FROM Customer WHERE Customer_No IN (SELECT Customer_No FROM Customer MINUS SELECT Customer_No FROM DVD_Purchase ) And I'm getting the following error message: Msg 156, Level 15, State 1, Line 123 Incorrect syntax near the keyword 'SELECT'. Msg 102, Level 15, State 1, Line 124 Incorrect syntax near ')'. As shown in the error message, Incorrect syntax near ')' which I'm unable to figure out. Other than that, can someone provide me the correct query? What is the minus in sql server?

Your answer

1 Answer

More SQL Server discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest SQL Server Blogs

Guides, tips and career advice on SQL Server from JanBask experts.