
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
What is the equivalent of EXCEPT in MySQL?
You cannot use EXCEPT in MySQL, instead use the NOT IN operator. Let us first create a table −
mysql> create table DemoTable ( Number1 int ); Query OK, 0 rows affected (0.71 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values(100); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values(200); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values(300); Query OK, 1 row affected (0.13 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable;
This will produce the following output −
+---------+ | Number1 | +---------+ | 100 | | 200 | | 300 | +---------+ 3 rows in set (0.00 sec)
Following is the query to create second table −
mysql> create table DemoTable2 ( Number1 int ); Query OK, 0 rows affected (0.52 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable2 values(100); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable2 values(400); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable2 values(300); Query OK, 1 row affected (0.11 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable2;
This will produce the following output −
+---------+ | Number1 | +---------+ | 100 | | 400 | | 300 | +---------+ 3 rows in set (0.00 sec)
Following is the query to use NOT IN operator in place of EXCEPT −
mysql> select Number1 from DemoTable where Number1 not in (SELECT Number1 FROM DemoTable2);
This will produce the following output −
+---------+ | Number1 | +---------+ | 200 | +---------+ 1 row in set (0.04 sec)
- Related Articles
- What is the PHP stripos() equivalent in MySQL?
- What is the MySQL SELECT INTO Equivalent?
- What is the PHP equivalent of MySQL's UNHEX()?
- What is the equivalent of Java long in the context of MySQL variables?
- What is the Java equivalent to MySQL's smallint?
- What is the equivalent of MySQL TIME_TO_SEC() method in PHP to convert datetime to seconds?
- What is the C++ equivalent of sprintf?
- What is Python equivalent of the ! operator?
- Is there PHP basename() equivalent in MySQL?
- What is the equivalent of SQL “like” in MongoDB?
- What is the equivalent of C# namespace in Java?
- Except not working in MySQL?
- The equivalent of SQL Server function SCOPE_IDENTITY() in MySQL?
- What is the equivalent of a VB module in C#?
- What is the equivalent of Java static methods in Kotlin?

Advertisements