News and Information for the Data Integration community

March 2007

 

SAP related solutions

Sage Software related solutions

Data migration solutions

Software Labs showcased in a Microsoft casestudy

Weekly Webinar on xFusion. Register via email to:
info@softlabsco.com

Newsletter Unsubscribe

More Newsletters

Most Recent

Feb 2007

Jan 2007

Dec 2006

Nov 2006

SQL Outer Joins

It seems to be a popular misconception that the number of rows

returned by a left outer join must match the number of rows in the left table. In this short article, Dr. Pradeep Tapadiya explains the inner workings of a SQL outer join.

Announcements

Latest happenings in xFusion and at Software Labs.

Did you know?


From the support desk

 
 

SQL Outer Joins
Author: Dr. Pradeep Tapadiya

 


It seems to be a popular misconception that the number of rows returned by a left outer join must match the number of rows in the left table. In this article, I will explain the inner workings of a SQL outer join to clear such misconceptions. Enjoy! – Pradeep

Any type of SQL join effectively multiplies the rows in the left table with the rows in the right table. An INNER JOIN acts as a filter that shows only those rows where the key fields have the same value. AN OUTER JOIN is used to include the rows that are "missing" in an inner join.

Consider the following two tables - Customers and Orders.

CustomerID Name
5001 Clark Kent
5002 Peter Parker
5003 Bruce Banner
OrderID CustomerID Quantity
10001 5001 5
10002 5003 10
10003 5001 3

Now, let's run the following query that performs a left outer join:

  SELECT Name, Quantity
FROM ( [Customers] LEFT OUTER JOIN [Orders]
ON [Customers].[CustomerID] = [Orders].[CustomerID])

Here is the resulting table:

Name Quantity
Clark Kent 3
Clark Kent 5
Peter Parker (null)
Bruce Banner 10

There are two things worth noting here:

  • Peter Parker does not have any associated quantity. This is because Peter Parker never placed any order. For any unmatched values, LEFT OUTER JOIN places a (null) value for the selected fields from the right table.

  • The number of rows in the result are more than the number of rows in Customers table

The number of resulting rows is a function of two variables a) the number of rows in the left table and b) whether the join condition results in a one-to-one match or a one-to-many match for each individual row of the left table.

If a row from the left table matches just one row in the right table(or does not match any row), it contributes towards one row in the resulting table.

If a row from the left table matches n number of rows in the right table, it contributes toward n rows in the resulting table.

Essentially, the number of rows in the resulting table will be either equal to or greater than the number of rows in the left table.

A RIGHT OUTER JOIN is simliar to a LEFT OUTER JOIN except the roles of the tables are reversed. For any unmatched value from right to left, (null) values are placed in the selected fields of the left table.

A FULL OUTER JOIN fills (null) values for unmatched left-to-right and unmatched right-to-left rows.

Let us look at a couple of cases where outer joins are very useful.

Identify missing information
The following query identifies all the customers who have not placed any orders.

  SELECT Name
FROM ( [Customers] LEFT OUTER JOIN [Orders]
ON [Customers].[CustomerID] = [Orders].[CustomerID])
WHERE [Orders].[Quantity] IS NULL


Creating aggregate data reports

The following query reports the number of orders placed by each customer:

  SELECT CustomerID, COUNT([Orders].[OrderID])
FROM ( [Customers] LEFT OUTER JOIN [Orders]
ON [Customers].[CustomerID] = [Orders].[CustomerID])
GROUP BY [Customers].[CustomerID]

Hope this gives you a better picture on how outer joins work.

New Partners

We are happy to announce the addition of I-Business Network to our growing list of partners. xFusion will help them to streamline customer migrations, and integrating customer data across business applications.

Improving Data Quality

Bad data can mean big problems for all aspects of a business. xFusion provides the tools you need to help improve your data, and improve your business. Request a Webex demo this week to see xFusion in action. Email info@softlabsco.com for more info.

New xFusion Community Forum
In an effort to expand our software support and improve knowledge transfer we have launched a new online forum. This forum is designed to help users and non-users learn more about our software solutions and capabilities for improved data management. Please sign up and contribute your ideas and feedback so that all will benefit. See xFusion Community Forum online here: http://forums.xfusiondn.com/

Did you know xFusion supports bulk uploading of data to SQL server and Oracle?

To achieve significant performance in data upload to SQL server or Oracle you can use the bulk insert option in xFusion. Read more…

Support Questions:

Dear Support,

I am attempting to do some manipulation to data within one column. How do I replace all periods, commas, and brackets with a blank entry? I am able to do them one at a time, but I was curious of the syntax to do all of them within one query if possible.

Here is the syntax I am using so far

 

RegexReplace("abc.ef-g","[.]","")
RegexReplace("abc.ef-g","[-]","")

I tried to use a semi colon (;) to terminate the line but that seemed to fail.
Any help is appreciated.
Thanks

Hi,

You are almost there. The same function RegexReplace can also be used to replace more than one character. The trick is to specify all the characters to be replaced within square brackets, as in the following example:

 

RegexReplace("abc.ef-g", "[,-.]", "")

The above statement will look for each of the character enclosed in square brackets [] and replace it with the third parameter. The output will be "abcefg"
Hope this helps.

Regards,
Support



Dear Support,
How can I put multiple functions in one transform query?
Thanks.

Hi,
You can put multiple transform functions together using Select transform function.
Example of Select statement is as below:

 

Select(

Left("Software Labs",8) as FirstName,
Right("Software Labs", 4) as LastName

)

Hope this helps.
Regards,
Support


Software Labs, Inc. 1225 Pleasant Grove Blvd. #100, Roseville CA 95768, USA
ph: 1-916-773-6272 fax: 916-773-6281 web: http://www.softlabsco.com email: info@softlabsco.com
unsubscribe via email: unsubscribe@softlabsco.com unsubscribe via web: click here