SQL Server BasicsWhat is SQL Server database?What is RDBMS?What is Normalization?Why we use Denormalization?What_is_SQL?What is PL/SQL?Difference between SQL and PL/SQLDatabase TableOne to One RelationshipOne to Many RelationshipMany to Many RelationshipMany to One RelationshipString Data TypesNumber Data TypesDate Data TypesOther Data TypesCreate DatabaseDrop DatabaseCreating and Managing Users in SQL ServerCreate TableAlter TableDrop TableConstraints in SQL serverPrimary KeyForeign KeyUnique KeyCandidate KeyComposite KeyDifference between primary key and candidate keyPrimary key and foreign key relationshipSurrogate KeyCascading Referential Integrity ConstraintsSelf Referential Integrity ConstraintsInsert into statementInsert multiple recordsUpdate statementDelete statementTruncate statementDifference between Delete and TruncateAlias in SQL ServerSelect statementSelect DistinctSelect TopSelect IntoNull Functions(ISNULL(),NULLIF(),COALESCE())Sub QueryIdentity ColumnSequence objectDifference between sequence and identity columnSQL Server ClausesWHERE ClauseOrder By ClauseTop N ClauseGroup By ClauseHaving ClauseDifference between Where and HavingSQL Server OperatorsArithmetic OperatorsComparison OperatorsLogical OperatorsBitwise OperatorsAny OperatorsAll OperatorsUnion OperatorsUnion All OperatorsDifference between Union and Union AllIntersect OperatorExcept OperatorDifference between Except and IntersectJoinsInner JoinLeft JoinRight JoinFull JoinSelf JoinCross JoinViewsWhat are views?Create views using SSMSIndexed ViewsComplex ViewsCheck Option in ViewCheck Encryption in ViewSchema Binding Option in ViewRead-only ViewsUpdatable ViewsAdvantages and disadvantages of viewsCreate multiple views on one tableCan we implement index on views?Can we Perform Insert, update, delete operation on views?Stored Procedure and FunctionsWhat are Stored Procedures?Why we use stored procedures?Passing parameters to Stored procedureUser-Defined FunctionsDifference between UDF and Stored procedurePre-Defined Functions@@Indentity and Scope_IndentityNULLIF, ISNULL and COALESCE

Difference between Except and Intersect

The main difference between the EXCEPT and INTERSECT operators in SQL is how they handle the result sets of multiple SELECT statements:

  1. EXCEPT: The EXCEPT operator is used to retrieve the distinct rows from the result set of the first SELECT statement that are not present in the result set of the second SELECT statement. It effectively subtracts the rows of one result set from another. The EXCEPT operator returns rows that exist in the first result set but not in the second result set.
  2. INTERSECT: The INTERSECT operator is used to retrieve the common rows between the result sets of two or more SELECT statements. It returns only the distinct rows that are present in all SELECT statements involved in the operation. The INTERSECT operator returns rows that exist in all result sets.
Here's a summary of the key differences between EXCEPT and INTERSECT:
  • Result Set: EXCEPT returns rows that exist in the first result set but not in the second result set, while INTERSECT returns rows that exist in all result sets.
  • Handling Duplicates: EXCEPT eliminates duplicate rows from the first result set, while INTERSECT eliminates duplicate rows from the combined result sets.
  • Distinctness: EXCEPT returns distinct rows, while INTERSECT returns distinct common rows.
  • Syntax: The syntax for EXCEPT and INTERSECT is similar, but the keyword used is different.

To decide whether to use EXCEPT or INTERSECT, consider your specific requirements. If you want to retrieve rows that exist in one result set but not in another, use EXCEPT. If you want to retrieve the common rows between multiple result sets, use INTERSECT.
It's important to note that the columns, their data types, and their order must match in the SELECT statements for both EXCEPT and INTERSECT operators to work correctly.