Saturday, November 7, 2009

Outer JOIN Querie



OUTER JOIN

If we have to select elements in a table regardless of whether they are present in the second

table? We will now need to use the SQL OUTER JOIN command.

Let's assume that we have the following two tables,

Table Shop



Table Graphy


and we want to find out the sales amount for all of the stores. If we do a regular join, we will not be able to get what we want because we will have missed "New York," since it does not appear in the Shop table. Therefore, we need to perform an outer join on the two tables above:

SELECT A1.store_name, SUM(A2.Sales) SALES
FROM Graphy A1, Shop A2
WHERE A1.store_name = A2.store_name (+)
GROUP BY A1.store_name


Note that in this case, we are using the Oracle syntax for outer join.

Result:
























No comments:

Post a Comment