Latest Code Tutorials

SQL Except Clause Example | Except Statement In SQL


SQL Except Clause Example | Except Statement In SQL is today’s topic. The SQL EXCEPT operator is used to combine two select statements, which in turn returns the row that is present in the first select statement and not in the second select statement. This Clause acts like a subtract operation that we perform in sets and Venn diagrams.

SQL Except Clause Example

In SQL, EXCEPT returns those tuples that are returned by the first SELECT operation, and not returned by the second SELECT operation.

#Pictorial Representation


SQL Except Clause

From above you can see that no common records will be displayed between two queries i.e., only Query1 will return all its rows.

 Each Select statement within an EXCEPT query must have the same number of fields in the result sets having similar data types.


Select column(s) from table_name1 where(condition)
Select column(s) from table_name2 where(condition).


  1. Column(s) represents the name of the columns.
  2. Table_name1 and Table_name2 are the names of the tables.
  3. Where(condition) is the condition to be imposed on select statements.
  4. EXCEPT is the operator who acts like a minus operator on select statements.

Let’s clear the above operations with examples.

Consider Tables: (Students) and (Course)


Roll Name City
1 Rohit Patna
2 Shouvik Jalandhar
3 Shubh Kolkata
4 Karan Allahabad
5 Shivam Palampur
6 Karan Dhulian



Name Course
Shubh Data Science
Rohit Data Science
Shivam Android Development



Select name from Students
Select name from Course;





In the above query name of students were declared who have not registered for any of the courses. So, Shouvik and Karan were displayed in the resulting set because they had not logged in any of the courses.


You can see that in the above query Karan was displayed only one time. So, to retain duplicates, we have to use EXCEPTALL clause.

The corresponding columns in the each of the SELECT statements must have similar data types.

The EXCEPT operator returns all records from the first SELECT statement that are not in the second SELECT statement.

See the following query.

Select name from Students
Select name from Course




So, you can see that Karan has been displayed twice.


Except clause removes duplicates from the resulting set whereas NOT IN clause does not remove duplicates from the resulting set.


MySQL does not support EXCEPT CLAUSE. So, it is better to use in SQL SERVER.

Finally, SQL Except Clause Example | Except Statement In SQL is over.

Leave A Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.