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

SQL - Full Join

In SQL Server, a FULL JOIN (also known as a full outer join) combines the results of both the LEFT JOIN and the RIGHT JOIN. It returns all the rows from both the left and right tables, matching rows where the join condition is met and including NULL values for non-matching rows.

The basic syntax for performing a FULL JOIN in SQL Server is as follows:


SELECT column_list
FROM table1
FULL JOIN table2 ON join_condition;

In this syntax, column_list represents the columns you want to select from the tables involved in the join operation. table1 is the left table, and table2 is the right table you want to join. The join_condition specifies the relationship between the tables.

The join condition is typically defined using the equality operator (=) to match values in the related columns of the joined tables. For example, if the related columns are "ID" in table1 and "ID" in table2, the join condition would be table1.ID = table2.ID.

Here's an example to illustrate the usage of a FULL JOIN:

Consider two tables, "Customers" and "Orders", with the following structures:

Customers Table
ID Name Age
1 John 25
2 Jane 30
3 Mike 35
Orders Table
OrderID Amount CustID
101 100.00 1
102 200.00 2
103 150.00 1

To retrieve all the customers and orders, including unmatched rows from both tables, you can use a FULL JOIN as follows:


SELECT Customers.Name, Orders.OrderID, Orders.Amount
FROM Customers
FULL JOIN Orders ON Customers.ID = Orders.CustID;

In the above query, we select the customer name from the "Customers" table and the order ID and amount from the "Orders" table. We perform a full join between the two tables, connecting them based on the customer ID (ID) column in the "Customers" table and the customer ID (CustID) column in the "Orders" table.

The full join ensures that all rows from both the left table ("Customers") and the right table ("Orders") are included in the result set. If there is a match, the corresponding customer and order information is displayed. If there is no match, NULL values are returned for the non-matching columns.

The output of the query would be:

Name OrderID Amount
John 101 100.00
John 103 150.00
Jane 102 200.00
Mike NULL NULL

As you can see, the result set includes all the customers and orders, even when there is no match between them. In this case, Mike doesn't have any orders, so NULL values are displayed for the order-related columns. Similarly, if there were customers without corresponding orders, NULL values would be displayed for the customer-related columns.

In summary, a FULL JOIN in SQL Server combines the results of both the LEFT JOIN and the RIGHT JOIN. It returns all the rows from both tables