Wednesday, November 13, 2013

SQL:SQL FULL OUTER JOIN-SQL UNION -- SQL UNION ALL

Refer the Source Video: SQL Server join :- Inner join,Left join,Right join and full outer join

Full outer join=Result of (Inner join (common records) + Left Outer Join + Right Outer Join)


Source: SQL FULL OUTER JOIN Keyword

SELECT Customers.CustomerName, Orders.OrderID
FROM Customers
FULL OUTER JOIN Orders
ON Customers.CustomerID=Orders.CustomerID
ORDER BY Customers.CustomerName;

Note: The FULL OUTER JOIN keyword returns all the rows from the left table (Customers), and all the rows from the right table (Orders). If there are rows in "Customers" that do not have matches in "Orders", or if there are rows in "Orders" that do not have matches in "Customers", those rows will be listed as well.


Source: SQL UNION -- SQL UNION ALL 

SELECT City FROM Customers
UNION
SELECT City FROM Suppliers
ORDER BY City;

Note: UNION cannot be used to list ALL cities from the two tables. If several customers and suppliers share the same city, each city will only be listed once. UNION selects only distinct values. Use UNION ALL to also select duplicate values!

No comments:

Post a Comment