Answers

Question and Answer:

  Home  Basic SQL Server

⟩ Tell me what is use of EXCEPT clause? How it differs from NOT IN clause?

-When we combine two queries using EXCEPT clause, it will returns distinct rows from the first SELECT statement that are not returned by the second one.

-EXCEPT clause works the same way as the UNION operator of SQL and MINUS clause in Oracle.

-The syntax of EXCEPT clause is as follow

SELECT column1 [, column2 ]

FROM table1 [, table2 ]

[WHERE condition]

EXCEPT

SELECT column1 [, column2 ]

FROM table1 [, table2 ]

[WHERE condition]

-The difference between EXCEPT and NOT IN clause is EXCEPT operator returns all distinct rows from the rows returned by first select statement which does not exist in the rows returned by second select statement. On the other hand “NOT IN” will return all rows from returned by first select statement which does not exist in the rows returned by second select statement.

 122 views

More Questions for you: