MySQL Wildcards

MySQL Wildcards

MySQL Aliases

MySQL Aliases

MySQL Data Types

MySQL Data Types

MySQL Interview Questions

MySQL Interview Questions and Answers


MySQL MINUS Operator

The MySQL does not support MINUS operator. However you can still achive MINUS with MySQL join. Basically, MINUS operator compares results of two SELECT statement and returns distinct rows from the first SELECT statement that aren't present in the second SELECT statement.

MySQL MINUS OPERATOR Syntax

To compares results of two SELECT statement and returns distinct rows from the first SELECT statement that aren't present in the second SELECT statement, use the following syntax:

Syntax

SELECT col1, col2 FROM tablename1
MINUS
SELECT col1, col2 FROM tablename2;

Parameters:

tablename1 & 2: The table name from which you want to achive MINUS operator.

.

MySQL MINUS OPERATOR example using LEFT JOIN

The following MySQL, is using LEFT JOIN to perform MINUS operator in MySQL:

Example

SELECT A.firstName, A.lastName
FROM tblcustomer A 
LEFT JOIN tblcustomerloan B
ON A.firstName = B.firstName AND A.lastName = B.lastName
WHERE B.firstName IS NULL; 

Note:

In the above example, the LEFT JOIN is uses to achive MINUS with MySQL join.

You can use MySQL Command Line Client to use MINUS in MySQL use join to achive MINUS operator. It will look like this: