SQL Database Concepts Question:
Download Questions PDF

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

Answer:

-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.

Download Basic SQL Server Interview Questions And Answers PDF

Previous QuestionNext Question
Tell me what is difference between clustered and non clustered index?Explain what is lock escalation?