Database Joins

Post here with questions about customer reporting with Crystal or other methods.
Post Reply
User avatar
Oso Rojo
Site Admin
Posts: 7
Joined: Wed Apr 12, 2017 5:47 pm

Database Joins

Post by Oso Rojo » Sat Apr 15, 2017 4:34 pm

Unless you are making a very, very simple report, like maybe a list of employees, then you are going to have to join database tables. Joins are actually a very simple subject, if you organize them together. One of the things that makes the joins subject needlessly complex is that different products call the same type of joins different names. For this discussion I will stay with Crystal's syntax because that is the audience of new report writers.

Crystal offers four different types of joins. There are many other types in SQL, but Crystal offers the basics that cover 99% of the needs. These joins are:
  • Inner
    Left Outer
    Not Equal
    Full Outer
Let's look at each of them.

Inner
Image
Let's say we are joining Jobs and Customers. This join would give us only the records that have Jobs and Customers in the same record. If a Job was not yet connected to a Customer, then it would not display. The same for a Customer that was not linked to a Job, it would not display.

Left Outer
Image
Using the same example from above, where table 1 on the left is the Jobs table, this join gives us all Jobs whether they have a Customer linked or not. The only Customer information returned from table 2 would be for Customers that are linked to Jobs. Customers not linked to Jobs are not returned.

Not Equal
Image
This is a slightly odd join, it returns records from Jobs that don't have customers and Customers that don't have jobs.

Full Outer
Image
In this case the join will return all Jobs and all Customer records. Those that don't have linked records will return empty fields for the missing data.

In writing this post I leaned on C.L. Moffatt's diagrams from his very informative post on codeproject.com. I recommend that you check it out. Do keep in mind his naming of the types of joins follow a different syntax than Crystal.
https://www.codeproject.com/articles/33 ... -sql-joins

The W3Shool always provides great information on SQL issues, so check them out here for more details on joins.
https://www.w3schools.com/sql/sql_join.asp

So you can see that when taken in scope of what Crystal can do, joins are straight forward and easy to understand.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest