{"id":1180,"date":"2025-01-13T21:15:03","date_gmt":"2025-01-14T02:15:03","guid":{"rendered":"https:\/\/pressbooks.bccampus.ca\/nelson\/chapter\/chapter-10-relational-algebra-relational-calculus-and-relational-theory\/"},"modified":"2025-01-13T21:32:04","modified_gmt":"2025-01-14T02:32:04","slug":"chapter10thirdedition","status":"publish","type":"chapter","link":"https:\/\/pressbooks.bccampus.ca\/nelson\/chapter\/chapter10thirdedition\/","title":{"raw":"Chapter 10 Relational Algebra, Relational Calculus, and Relational Theory","rendered":"Chapter 10 Relational Algebra, Relational Calculus, and Relational Theory"},"content":{"raw":"<div class=\"chapter-10-relational-algebra,-relational-calculus,-and-relational-theory\">\r\n<p class=\"import-Normal\">Original Material to the textbook: Fred Strickland<\/p>\r\n\r\n<h2>Learning Outcomes<\/h2>\r\n<table style=\"width: 467.5pt\">\r\n<tbody>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"background-color: transparent;border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\"><strong>Computing Sub Discipline<\/strong><\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"background-color: transparent;border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\"><strong>Document Code, Reference Code, and Page Number<\/strong><\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"background-color: transparent;border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\"><strong>Text<\/strong><\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\" style=\"height: 67.9pt\">\r\n<td class=\"TableGrid-C\" style=\"background-color: transparent;border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Computer Science<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"background-color: transparent;border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">CS2013<\/p>\r\n<p class=\"import-Normal\">IM\/Relational Databases<\/p>\r\n<p class=\"import-Normal\">(Pages 115-116)<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"background-color: transparent;border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">3. Demonstrate use of the relational algebra operations from mathematical set theory (union, intersection, difference, and Cartesian product) and the relational algebra operations developed specifically for relational databases (select (restrict), project, join, and division). [Usage]<\/p>\r\n<p class=\"import-Normal\">4. Write queries in the relational algebra. [Usage]<\/p>\r\n<p class=\"import-Normal\">5. Write queries in the tuple relational calculus. [Usage]<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\" style=\"height: 67.9pt\">\r\n<td class=\"TableGrid-C\" style=\"background-color: transparent;border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\"><\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"background-color: transparent;border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">CS2023<\/p>\r\n<p class=\"import-Normal\">DM-Querying: Query Construction<\/p>\r\n<p class=\"import-Normal\">(Page 118)<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"background-color: transparent;border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">KA Core 2. Relational Algebra<\/p>\r\n<p class=\"import-Normal\">Non-core 4. Relational Calculus<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\" style=\"height: 82.75pt\">\r\n<td class=\"TableGrid-C\" style=\"background-color: transparent;border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Information Technology<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"background-color: transparent;border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">IT2017<\/p>\r\n<p class=\"import-Normal\">ITE-IMA-05 Database organizational architecture [L3]<\/p>\r\n<p class=\"import-Normal\">(Page 93)<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"background-color: transparent;border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">a. Demonstrate select, project, union, intersection, set difference, and natural join relational operations using simple example relations provided.<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr>\r\n<td><\/td>\r\n<td><\/td>\r\n<td><\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n<h2>Introduction to Chapter 10<\/h2>\r\n<p class=\"import-Normal\">We have been looking at relational DBMS from a hands-on or application viewpoint. And we have touched upon the different DBMSs. We have discovered that SQL-92 is not fully implemented by these DBMSs and that there are extensions.<\/p>\r\n<p class=\"import-Normal\">How do the various DBMS groups discuss things? These groups could use relational algebra and relational calculus as the common language.<\/p>\r\n<p class=\"import-Normal\">As textbook authors Thomas Connolly and Caroly Begg wrote:<\/p>\r\n<p class=\"import-Normal\" style=\"margin-left: 36pt\">Both the algebra and the calculus are formal, non-user-friendly languages. They have been used as the basis for other, higher-level Data Manipulation Languages (DML) for relational databases. They are of interest because they illustrate the basic operations required of any DML and because they serve as the standard for comparison for other relational languages.<\/p>\r\n<p class=\"import-Normal\" style=\"margin-left: 36pt\">The relational calculus is used to measure the selective power of relational languages. A language that can be used to produce any relational that can be derived using the relational calculus is said to be relationally complete. Most relational query languages are relatively complete but have more expressive power than the relational algebra or relational calculus because of additional operations such as calculated, summary, and ordering functions.<\/p>\r\n<p class=\"import-Normal\">Now you understand the need for this chapter.<\/p>\r\n\r\n<h2>The Third Edition Style Guide<\/h2>\r\n<p class=\"import-Normal\">This is the style guide that this book will follow for this chapter and for the other chapters.<\/p>\r\n\r\n<table style=\"width: 229.25pt\">\r\n<tbody>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"background-color: transparent;border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Naming Convention:<\/p>\r\n\r\n<ul>\r\n \t<li>All English names<\/li>\r\n \t<li>Plural table names<\/li>\r\n \t<li>Singular column names<\/li>\r\n \t<li>Capitalized words<\/li>\r\n \t<li>Pascal Case for composite names<\/li>\r\n \t<li>No underscores or special characters<\/li>\r\n \t<li>No unique SQL commands<\/li>\r\n \t<li>No object prefixes<\/li>\r\n<\/ul>\r\n<p class=\"import-Normal\">Using the IE\u2019s Notation with Crow\u2019s Foot Notation.<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr>\r\n<td><\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n<p class=\"import-Normal\">Figure 10.1 The database style guide. Adapted from https:\/\/vertabelo.com\/blog\/database-schema-naming-conventions\/<\/p>\r\n<p class=\"import-Normal\">The examples will conform to the style guide.<\/p>\r\n\r\n<h2>Regular Algebra and Relational Algebra<\/h2>\r\n<p class=\"import-Normal\">Regular Algebra is a mathematical system that has the following:<\/p>\r\n\r\n<ul>\r\n \t<li><em>Operands<\/em>: Variables or values<\/li>\r\n \t<li><em>Operators<\/em>: Symbols denoting what will be done to the operands.<\/li>\r\n<\/ul>\r\n<p class=\"import-Normal\">Relational Algebra is a system that has the following:<\/p>\r\n\r\n<ul>\r\n \t<li><em>Operands<\/em> are relations OR variables that represent relations.<\/li>\r\n \t<li><em>Operators<\/em> that are designed to do the most common actions that we need to do with relations in a database.<\/li>\r\n \t<li>Uses <em>set operations<\/em> from mathematical set theory.\r\n<ul>\r\n \t<li>Union, Intersection, Set Difference, and Cartesian Product<sup class=\"import-FootnoteReference\"><a id=\"sdfootnote1anc\" href=\"#sdfootnote1sym\">1<\/a><\/sup>.<\/li>\r\n<\/ul>\r\n<\/li>\r\n<\/ul>\r\n<p class=\"import-Normal\">To sum it up, <em>relational algebra<\/em> collects instances of relations as input and gives occurrences of relations as outputs.<\/p>\r\n<p class=\"import-Normal\">Textbook authors Thomas Connolly and Carolyn Begg wrote:<\/p>\r\n<p class=\"import-Normal\" style=\"margin-left: 36pt\">The relational algebra is a theoretical language with operations that work on one or more relations to define another relation without changing the original relation(s). Thus, both the operands and the results are relations, and so the output from one operation can become the input to another operation. This allows expressions to be nested in the relational algebra, just as we can nest arithmetic operations. This property is called closure; relations are closed under the algebra, just as numbers are closed under arithmetic operations.<\/p>\r\n<p class=\"import-Normal\">Figure 10.2 shows the differences between regular algebra and relational algebra.<\/p>\r\n\r\n<table>\r\n<tbody>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\" style=\"text-align: center\"><strong>Regular Algebra<\/strong><\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\" style=\"text-align: center\"><strong>Relational Algebra<\/strong><\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\" style=\"margin-left: 18pt\">Add +<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\" style=\"margin-left: 36pt\">Union U<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\" style=\"margin-left: 18pt\">Subtract -<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\" style=\"margin-left: 36pt\">Set difference \u2013<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\" style=\"margin-left: 18pt\">Multiple X or a dot<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\" style=\"margin-left: 36pt\">Cartesian product X<\/p>\r\n<p class=\"import-Normal\" style=\"margin-left: 54pt\">Also known as \u201cCross Product.\u201d<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\" style=\"margin-left: 18pt\">Divide \/ or \u00f7<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"background-color: transparent;border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\" style=\"margin-left: 36pt\">Division \u00f7<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\" style=\"margin-left: 18pt\">Factoring elements into small elements (Such as X<sup>2<\/sup> + 4X + 4 into (x + 2)(X + 2).)<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"background-color: #d9d9d9;border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\"><\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr>\r\n<td><\/td>\r\n<td><\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n<p class=\"import-Normal\">Figure 10.2 The differences between regular algebra and relational algebra.<\/p>\r\n<p class=\"import-Normal\">Set operations have one more operation that does not exist in regular algebra:<\/p>\r\n\r\n<ul>\r\n \t<li><em>Intersection<\/em> \u2229<\/li>\r\n<\/ul>\r\n<p class=\"import-Normal\">Relational databases go beyond the standard set operations. So the following have been added:<\/p>\r\n\r\n<ul>\r\n \t<li><em>Selection<\/em> \u03c3 (The lower case Greek letter sigma)<sup class=\"import-FootnoteReference\"><a id=\"sdfootnote2anc\" href=\"#sdfootnote2sym\">2<\/a><\/sup><\/li>\r\n \t<li><em>Projection<\/em> \u03c0 (The lower case Greek letter pi)<\/li>\r\n \t<li><em>Renaming<\/em> \u03f8 (The lower case Greek letter rho)<\/li>\r\n \t<li><em>Join<\/em> \u22c8<\/li>\r\n<\/ul>\r\n<h3>Recall Entity Relationship Model Rules and Relational Scheme Notes<\/h3>\r\n<p class=\"import-Normal\">Recall from Chapter 5 where we looked at entity relationship data model with integrity rules and constraints. We used some symbols for indicating the functional dependencies.<\/p>\r\n\r\n<ul>\r\n \t<li>SIN ---&gt; Name, Address, Birthdate\r\n<ul>\r\n \t<li>The SIN determines Name, address, and Birthdate. For any given SIN, we can determine any other attribute in that record.<\/li>\r\n<\/ul>\r\n<\/li>\r\n \t<li>SIN, Course ---&gt; DateCompleted\r\n<ul>\r\n \t<li>The SIN and the Course determine the DateCompleted. The SIN and Course could be used to form a composite PK. Or something else might be serving in that role. So we could be working with the candidate key or with an alternative key.<\/li>\r\n<\/ul>\r\n<\/li>\r\n \t<li>ISBN ---&gt; Title\r\n<ul>\r\n \t<li>This is an example of something that determines only one thing (dependent)<\/li>\r\n<\/ul>\r\n<\/li>\r\n<\/ul>\r\n<p class=\"import-Normal\">Recall the relational scheme R(ABCDE). We worked with a table like the following:<\/p>\r\n<p class=\"import-Normal\"><img src=\"https:\/\/pressbooks.bccampus.ca\/nelson\/wp-content\/uploads\/sites\/2211\/2025\/01\/image1-3.jpeg\" alt=\"image\" width=\"170.105196850394px\" height=\"260.586666666667px\" \/><\/p>\r\n<p class=\"import-Normal\">Figure 10.3 A relation table.<\/p>\r\n\r\n<h3>Unary Relational Operation: Selection<\/h3>\r\n<p class=\"import-Normal\">This is one of the operations developed specifically for relational databases. Recall that in SQL we were able to select which columns would appear in the output and we were able to use the WHERE clause to obtain a subset of the rows. In relational algebra, we would express this with the Greek letter \u03c3 and we use this to choose a subset of tuples from a relation that satisfies a selection condition.<\/p>\r\n<p class=\"import-Normal\">Do not confuse the selection operator with the SQL key word \u201cSELECT.\u201d The former finds the tuples that satisfy a condition whereas the later determines which columns will be selected from the source database tables.<\/p>\r\n<p class=\"import-Normal\">Figure 10.4 shows two selection queries in both SQL and relational algebra.<\/p>\r\n\r\n<table>\r\n<tbody>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Select the Employee tuples where the DepartmentID is 4<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Select the Employee tuples where the Salary is greater than $30,000<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">SELECT * FROM Employees<\/p>\r\n<p class=\"import-Normal\">WHERE DepartmentID = \u20184\u2019<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">SELECT * FROM Employees<\/p>\r\n<p class=\"import-Normal\">WHERE Salary &gt; 30000<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">\u03c3<sub>DepartmentID<\/sub> <sub>= 4<\/sub> (Employees)<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">\u03c3<sub>Salary<\/sub> <sub>&gt; 30000<\/sub> (Employees)<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr>\r\n<td><\/td>\r\n<td><\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n<p class=\"import-Normal\">Figure 10.4 The differences between SQL command and relational algebra.<\/p>\r\n<p class=\"import-Normal\">The relational algebra expression has the Greek letter and the table name on the line and the conditional (the WHERE clause) is written as a subscript. Figure 10.5 shows this approach in a large font size.<\/p>\r\n\r\n<table>\r\n<tbody>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">\u03c3 <sub>&lt;selection condition as a subscript&gt; <\/sub>(Relation or table, normal line)<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr>\r\n<td><\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n<p class=\"import-Normal\">Figure 10.5 The syntax in large font..<\/p>\r\n<p class=\"import-Normal\">We can use the Boolean words of AND and OR. We can use comparison operators (=, &lt;, \u2264, &gt;, \u2265,\u2260). Figure 10.6 shows how this could be done with the two selects from Figure 10.4.<\/p>\r\n\r\n<table>\r\n<tbody>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Select the Employee tuples where the DepartmentID is 4 OR the Salary is greater than $30,000<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">SELECT * FROM Employees<\/p>\r\n<p class=\"import-Normal\">WHERE DepartmentID = \u20184\u2019 AND Salary &gt; 30000<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">\u03c3<sub>DepartmentID<\/sub> <sub>= 4<\/sub> <sub>AND <\/sub><sub>Salary <\/sub><sub>&lt; 30000<\/sub> (Employees)<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr>\r\n<td><\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n<p class=\"import-Normal\">Figure 10.6 An example of a compound SQL command with a WHERE clause and a compound clause in Relational Algebra<\/p>\r\n<p class=\"import-Normal\">Relational algebra uses a shorthand:<\/p>\r\n\r\n<ul>\r\n \t<li>The individual tuple is written as \u201ct.\u201d<\/li>\r\n \t<li>The relation is written as \u201cR.\u201d<\/li>\r\n \t<li>The attribute is written as \u201cAi.\u201d<\/li>\r\n \t<li>We can write this as t[Ai].<\/li>\r\n<\/ul>\r\n<p class=\"import-Normal\">We use the term \u201c<em>unary<\/em>,\u201d because we are dealing with a single relation or table and we are looking at each tuple individually.<\/p>\r\n<p class=\"import-Normal\">Look at this expression: |\u03c3<sub>c<\/sub> (R)| \u2264 |R|<\/p>\r\n<p class=\"import-Normal\">This is stating that the results of a selection will either be the whole table or a subset of the table. We can NEVER have a result set with more rows than what appeared in the original table. Again, we can NEVER have more columns than the original table.<\/p>\r\n<p class=\"import-Normal\">Terms may be used to describe the behavior of the selection.<\/p>\r\n\r\n<ul>\r\n \t<li><em>Selectivity of the condition<\/em>.\r\n<ul>\r\n \t<li>The fraction of tuples selected by a selection condition.<\/li>\r\n<\/ul>\r\n<\/li>\r\n \t<li><em>Commutative<\/em>\r\n<ul>\r\n \t<li>The sequence of the selects can be applied in any order.<\/li>\r\n \t<li>\u03c3<sub>&lt;Condition1&gt; <\/sub>(\u03c3<sub>&lt;Condition2&gt;) <\/sub>(R)) = \u03c3<sub>&lt;Condition2&gt; <\/sub>(\u03c3<sub>&lt;Condition1&gt;) <\/sub>(R))<\/li>\r\n<\/ul>\r\n<\/li>\r\n \t<li>Cascade or sequence\r\n<ul>\r\n \t<li>You could nest a query as done in commutative. Or you could express this as a conjunction (the key word AND).<\/li>\r\n \t<li>\u03c3<sub>&lt;Condition1&gt; <\/sub>(\u03c3<sub>&lt;Condition2&gt;) <\/sub>(R)) = \u03c3<sub>&lt;Condition2&gt; <\/sub>AND<sub>&lt;Condition1&gt;) <\/sub>(R))<\/li>\r\n<\/ul>\r\n<\/li>\r\n<\/ul>\r\n<p class=\"import-Normal\">We can use an example to understand the foregoing better. Vancouver British Columbia is home to Douglas College and to other institutions. We wish to find those individuals who have a connection to Douglas College as active students.<\/p>\r\n\r\n<ul>\r\n \t<li>Commutative: You could select all persons with a connection to Douglas College, then select out a list of active students. Or you could select out all active students from all institutions, then select out those with a connection to Douglas College. The resulting set would be the same.<\/li>\r\n \t<li>Cascade or sequence: Use either commutative approach or you could select all persons with a connection to Douglas College and a status as active student. And the order does not matter.<\/li>\r\n<\/ul>\r\n<h3>Unary Relational Operation: Projection<\/h3>\r\n<p class=\"import-Normal\">Projection is one of the operations developed specifically for relational databases. Selection will return all of the columns in a table. <em>Projection<\/em> permits us to select some of the columns from a table. The SQL key word \u201cSELECT\u201d does the same thing.<\/p>\r\n\r\n<table>\r\n<tbody>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">We want just an employee\u2019s last name, first name, and salary.<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">SELECT LastName, FirstName, Salary FROM Employees<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">\u03c0 <sub>LastName, FirstName, <\/sub><sub>Salary<\/sub>(Employees)<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr>\r\n<td><\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n<p class=\"import-Normal\">Figure 10.7 An example of projection in Relational Algebra<\/p>\r\n<p class=\"import-Normal\">Notice that the column names are written as subscripts.<\/p>\r\n<p class=\"import-Normal\">The projection operator has some interesting behaviors. If non-key attributes are used, then duplicate tuples are possible. If a key is used, then duplicate tuples cannot happen.<\/p>\r\n<p class=\"import-Normal\">In the formal relational model, duplicates are not permitted. In SQL, this is allowed. To have this behavior, we would use the key word DISTINCT. In some circles, this is called a multiset or a bag of tuples.<\/p>\r\n<p class=\"import-Normal\">Since projection is a special form of selection, the selection traits are present too. The exception is the property of commutativity. We cannot change the ordering of the columns in the column name list and have the same results in the output.<\/p>\r\n\r\n<h3>Unary Relational Operation: Renaming<\/h3>\r\n<p class=\"import-Normal\"><em>Renaming<\/em> is one of the operations developed specifically for relational databases. We use this operator in order to rename the output columns. Recall from regular algebra how you could use an immediate variable.<\/p>\r\n\r\n<table>\r\n<tbody>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\" style=\"text-align: center\"><strong>Example of an Algebra Problem Using Immediate Variables.<\/strong><\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">X + Y + Z<\/p>\r\n<p class=\"import-Normal\">Let A = X + Y<\/p>\r\n<p class=\"import-Normal\">Answer: A + Z<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr>\r\n<td><\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n<p class=\"import-Normal\">Figure 10.8 An example of an algebra problem using an immediate variable<\/p>\r\n<p class=\"import-Normal\">This is similar to software programming where a variable is declared to hold a temporary value. The following snippet of Java code shows how we can change the stored values.<\/p>\r\n\r\n<ul>\r\n \t<li>int A = 2;<\/li>\r\n \t<li>int B = 3;<\/li>\r\n \t<li>int C = 4;<\/li>\r\n \t<li>int temp;<\/li>\r\n \t<li>temp = A; \/\/ The variable temp is holding the value of 2.<\/li>\r\n \t<li>A = B; \/\/ The variable A has taken on the new value of 3.<\/li>\r\n \t<li>B = C; \/\/ The variable B has taken on the new value of 4.<\/li>\r\n \t<li>C = temp; \/\/ The variable C has taken on the new value of 2.<\/li>\r\n \t<li>System.out.println (\u201cA is \u201c + A + \u201c. B is \u201c + B + \u201c. C is \u201c + C + \u201c.\u201d);<\/li>\r\n \t<li>The output string is: A is 3. B is 4. C is 2.<\/li>\r\n<\/ul>\r\n<p class=\"import-Normal\">The variable temp preserves the value that was originally stored in the variable A. Otherwise, this value would be lost as soon as the value stored in B is sent to the variable A.<\/p>\r\n<p class=\"import-Normal\">Consider the example of retrieving the first name, last name, and salary of all employees who work in department number 5.<\/p>\r\n<p class=\"import-Normal\">We select all employees that work in department number 5. We limit the columns just to the first name, the last name, and the salary (via the projection operator). This could have been done in two steps. The output from the department number 5 employees would be stored in a temporary variable<sup class=\"import-FootnoteReference\"><a id=\"sdfootnote3anc\" href=\"#sdfootnote3sym\">3<\/a><\/sup>. Then we would take that temporary variable and feed it to the column selecting SQL.<\/p>\r\n\r\n<table>\r\n<tbody>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\" style=\"text-align: center\"><strong>Using Renaming Command<\/strong><\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">DEP5_EMPS &lt;--- \u03c3<sub>DepartmentID<\/sub><sub> = 5 <\/sub>(Employees)<\/p>\r\n<p class=\"import-Normal\">RESULTS &lt;--- \u03c0 <sub>FirstName, LastName, Salary <\/sub>(DEP5_EMPS )<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr>\r\n<td><\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n<p class=\"import-Normal\">Figure 10.9 An example of relational algebra using an immediate variable (DEPT_EMPS)<\/p>\r\n<p class=\"import-Normal\">Notice that in relational algebra that we do not use the Greek letter rho (\u03f8). Instead, we use the left pointing arrow with a long tail.<\/p>\r\n<p class=\"import-Normal\">We use the Greek letter rho (\u03f8) when we are discussing the options as for listing out the three forms of renaming:<\/p>\r\n<p class=\"import-Normal\" style=\"margin-left: 36pt\">\u03f8 <sub>S(<\/sub><sub>B1, B2, ..., Bn<\/sub>)(R) or \u03f8 <sub>S<\/sub>(R) or \u03f8<sub lang=\"el-GR\" xml:lang=\"el-GR\">(<\/sub><sub>B1, B2, ..., Bn)<\/sub>(R)<\/p>\r\n\r\n<ul>\r\n \t<li>Where \u03f8 is the RENAME operator.<\/li>\r\n \t<li>Where S is the new relation name.<\/li>\r\n \t<li>Where B1, B2, .., Bn are the new attribute names.<\/li>\r\n<\/ul>\r\n<p class=\"import-Normal\">A bit more explanation:<\/p>\r\n\r\n<ul>\r\n \t<li>\u03f8 <sub>S(<\/sub><sub>B1, B2, ..., Bn<\/sub>)(R) is renaming both the relation and its attributes<\/li>\r\n \t<li>\u03f8 <sub>S<\/sub>(R) is renaming only the relation<\/li>\r\n \t<li>\u03f8<sub lang=\"el-GR\" xml:lang=\"el-GR\">(<\/sub><sub>B1, B2, ..., Bn)<\/sub>(R) is renaming the attributes.<\/li>\r\n<\/ul>\r\n<p class=\"import-Normal\">How the attributes are ordered in the original relation is how the new attributes are ordered in the new relation.<\/p>\r\n\r\n<h3>Binary Relational Operation: Union and Intersection<\/h3>\r\n<p class=\"import-Normal\">Union and intersection are operations from set theory.<\/p>\r\n<p class=\"import-Normal\">We have worked with the SQL union command. An example will show how this operator is used.<\/p>\r\n<p class=\"import-Normal\">We wish to retrieve the Social Security numbers of all employees who either work in department 5 or directly supervise an employee who works in department 5.<\/p>\r\n<p class=\"import-Normal\">We could do this with temporary results via renaming and a union operation.<\/p>\r\n<p class=\"import-Normal\" style=\"margin-left: 36pt\">Result1 \u2190 \u03c0 Ssn(DEP5_EMPS)<\/p>\r\n<p class=\"import-Normal\" style=\"margin-left: 36pt\">Result2 \u2190 \u03c0 Super_ssn(DEP5_EMPS)<\/p>\r\n<p class=\"import-Normal\" style=\"margin-left: 36pt\">Result \u2190 Result1 U Result2<\/p>\r\n<p class=\"import-Normal\">The <em>u<\/em><em>nion<\/em> operation produces the tuples that are in either Result1 or Result2 or both while removing any duplicates.<\/p>\r\n<p class=\"import-Normal\">The intersection operation produces the tuples that are in both.<\/p>\r\n<p class=\"import-Normal\">In the relational database world, the two sets of tuples must be of the same type (union compatibility or type compatibility).<\/p>\r\n<p class=\"import-Normal\">We formally express <em>union compatibility<\/em> or <em>type compatibility<\/em> thusly:<\/p>\r\n\r\n<ul>\r\n \t<li>Two relations R(A1, A2, ..., An) and S(B1, B2, ..., Bn) are said to be union compatible (or type compatible) if they have the same degree<sup class=\"import-FootnoteReference\"><a id=\"sdfootnote4anc\" href=\"#sdfootnote4sym\">4<\/a><\/sup> n and if dom(Ai) = dom(Bi) for 1 \u2264 I \u2264 n.<\/li>\r\n \t<li>This means that the two relations have the same number of attributes (columns) and each corresponding pair of attributes has the same domain.<\/li>\r\n<\/ul>\r\n<p class=\"import-Normal\">Union and intersection are commutative operations.<\/p>\r\n\r\n<ul>\r\n \t<li><span lang=\"pt-BR\" xml:lang=\"pt-BR\">R <\/span><span lang=\"pt-BR\" xml:lang=\"pt-BR\">\u222a<\/span><span lang=\"pt-BR\" xml:lang=\"pt-BR\"> S = S <\/span><span lang=\"pt-BR\" xml:lang=\"pt-BR\">\u222a<\/span><span lang=\"pt-BR\" xml:lang=\"pt-BR\"> R <\/span><\/li>\r\n \t<li><span lang=\"pt-BR\" xml:lang=\"pt-BR\">R \u2229 S = S \u2229 R <\/span><\/li>\r\n<\/ul>\r\n<p class=\"import-Normal\">Union and intersection are associative operations. The grouping of the operations does not matter:<\/p>\r\n\r\n<ul>\r\n \t<li>R \u222a (S \u222a T) = (R \u222a S) \u222a T<\/li>\r\n \t<li>R \u2229 (S \u2229 T) = (R \u2229 S) \u2229 T<\/li>\r\n<\/ul>\r\n<h3>Binary Relational Operation: Set Difference<\/h3>\r\n<p class=\"import-Normal\"><em>Set difference<\/em> operation is from set theory.<\/p>\r\n<p class=\"import-Normal\">These are the tuples that are present in one relation, but not present in a second relation. We write this as R \u2013 S, which states that this includes all tuples that are in R, but are not in S.<\/p>\r\n<p class=\"import-Normal\">The two relations must be union compatibility or type compatibility.<\/p>\r\n<p class=\"import-Normal\">Commutative operations cannot be applied to a set difference action.<\/p>\r\n<p class=\"import-Normal\">In mathematics, an operation could be rewritten in different ways. Consider the following:<\/p>\r\n\r\n<ul>\r\n \t<li>9 times 10<\/li>\r\n \t<li>9 + 9 + 9 + 9 + 9 + 9 + 9 + 9 + 9 + 9<\/li>\r\n \t<li>10 + 10 + 10 + 10 +10 + 10 + 10 + 10 + 10<\/li>\r\n \t<li>10 times 10 \u2013 10<\/li>\r\n<\/ul>\r\n<p class=\"import-Normal\">Prove to yourself that the answer for each line is 90.<\/p>\r\n<p class=\"import-Normal\">In binary relations, you could do the same thing. You could rewrite an intersection action as a series of unions and set differences:<\/p>\r\n\r\n<ul>\r\n \t<li><span lang=\"pt-BR\" xml:lang=\"pt-BR\">R \u2229 S = ((R <\/span><span lang=\"pt-BR\" xml:lang=\"pt-BR\">\u222a<\/span> <span lang=\"pt-BR\" xml:lang=\"pt-BR\">S )<\/span><span lang=\"pt-BR\" xml:lang=\"pt-BR\"> \u2212 (R \u2212S )) \u2212 (S \u2212R)<\/span><\/li>\r\n<\/ul>\r\n<h3>Binary Relational Operation: Cartesian Product<\/h3>\r\n<p class=\"import-Normal\"><em>Cartesian <\/em><em>product<\/em> is an operation from set theory. This is also known as \u201ccross product.\u201d If we drop the requirement that a relation must be union compatible, then you could have an output that is larger than either relation. The result is a new element by combining every member tuple from one relation set with every member tuple from the other relation set. In formal expression, we would write this as:<\/p>\r\n\r\n<ul>\r\n \t<li>R(A1, A2, ..., An) X S(B1, B2, ..., Bm) is a relation Q with degree n + m attributes Q(A1, A2, ..., An, B1, B2, ..., Bm), in that order.<\/li>\r\n<\/ul>\r\n<p class=\"import-Normal\">If you create a join command and leave off the WHERE clause, then the result would be a Cartesian product. Suppose we wanted to output a list of every female employee with their children. We would need to include a WHERE clause of the female employee\u2019s company ID number from two tables (the Employees table and the Dependents table). If the WHERE clause is omitted, then the output would have EVERY dependent name combined with EVERY female employee. Clearly this is not very useful.<\/p>\r\n<p class=\"import-Normal\">Is there a place for the Cartesian product? Yes. Suppose you are in your favorite breakfast caf\u00e9. The menu has two columns as shown in Figure 10.10:<\/p>\r\n\r\n<table>\r\n<tbody>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\" style=\"text-align: center\"><strong>Proteins<\/strong><\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\" style=\"text-align: center\"><strong>Sides<\/strong><\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Chicken<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Mushroom Pasta<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Salmon<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Spinach and Mushrooms<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Cod<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Slaw<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Scallops<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Sun-dried tomatoes<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Octopus<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Arugula salad<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"background-color: #d9d9d9;border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\"><\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Broccoli<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr>\r\n<td><\/td>\r\n<td><\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n<p class=\"import-Normal\">Figure 10.10 An example of a menu with five proteins and six sides<\/p>\r\n<p class=\"import-Normal\">You do not wish to eat the same combination twice in a 30-day period. Using mathematics, you know that 5 times 6 is 30. And you could work this out by hand:<\/p>\r\n\r\n<table>\r\n<tbody>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Chicken<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Salmon<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Cod<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Scallops<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Octopus<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Mushroom Pasta<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Mushroom Pasta<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Mushroom Pasta<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Mushroom Pasta<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Mushroom Pasta<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Spinach and Mushrooms<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Spinach and Mushrooms<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Spinach and Mushrooms<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Spinach and Mushrooms<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Spinach and Mushrooms<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Slaw<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Slaw<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Slaw<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Slaw<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Slaw<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Sun-dried tomatoes<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Sun-dried tomatoes<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Sun-dried tomatoes<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Sun-dried tomatoes<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Sun-dried tomatoes<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Arugula salad<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Arugula salad<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Arugula salad<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Arugula salad<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Arugula salad<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Broccoli<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Broccoli<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Broccoli<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Broccoli<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Broccoli<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr>\r\n<td><\/td>\r\n<td><\/td>\r\n<td><\/td>\r\n<td><\/td>\r\n<td><\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n<p class=\"import-Normal\">Figure 10.11 Working out by hand the 30 possible combinations<\/p>\r\n<p class=\"import-Normal\">Using Cartesian product or leaving off the WHERE clause, the output would be as follows:<\/p>\r\n\r\n<table>\r\n<tbody>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Chicken<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Mushroom Pasta<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Chicken<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Spinach and Mushrooms<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Chicken<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Slaw<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Chicken<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Sun-dried tomatoes<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Chicken<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Arugula salad<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Chicken<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Broccoli<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Salmon<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Mushroom Pasta<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Salmon<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Spinach and Mushrooms<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Salmon<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Slaw<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Salmon<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Sun-dried tomatoes<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Salmon<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Arugula salad<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Salmon<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Broccoli<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Cod<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Mushroom Pasta<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Cod<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Spinach and Mushrooms<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Cod<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Slaw<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Cod<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Sun-dried tomatoes<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Cod<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Arugula salad<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Cod<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Broccoli<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Scallops<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Mushroom Pasta<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Scallops<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Spinach and Mushrooms<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Scallops<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Slaw<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Scallops<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Sun-dried tomatoes<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Scallops<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Arugula salad<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Scallops<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Broccoli<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Octopus<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Mushroom Pasta<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Octopus<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Spinach and Mushrooms<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Octopus<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Slaw<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Octopus<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Sun-dried tomatoes<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Octopus<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Arugula salad<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Octopus<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Broccoli<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr>\r\n<td><\/td>\r\n<td><\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n<p class=\"import-Normal\">Figure 10.12 Using Cartesian product to obtain the 30 possible combinations<\/p>\r\n\r\n<h3>Binary Relational Operation: Join Operation<\/h3>\r\n<p class=\"import-Normal\"><em>Join<\/em><em> operation<\/em> is an operation from set theory. A relational database is powerful, because of the ability to pull data from two or more tables. The output could have more fields or columns than one of the input tables. This is similar to the traits of a Cartesian product. The difference is that we use a WHERE clause to select out the useful rows.<\/p>\r\n<p class=\"import-Normal\">As Thomas Connolly and Carolyn Begg pointed out:<\/p>\r\n\r\n<ul>\r\n \t<li>Join is one of the most difficult operations to implement efficiently in a\u2026 [relational] DBMS and is one of the reasons why relational systems have intrinsic performance problems.<\/li>\r\n<\/ul>\r\n<p class=\"import-Normal\">Imagine that we wish to retrieve the name of each manager for each department in an organization. The Departments table contains the SSN for the manager. The Employees table contains the names of the managers. Recall that we used normalization and that is why the managers\u2019 names and other details are not stored in the Departments table. The manager\u2019s SSN is a foreign key in the Departments table. Here is the join command as expressed in relational algebra:<\/p>\r\n\r\n<ul>\r\n \t<li>DepartmentManager \u2190Departments \u22c8 <sub>ManagerSSN<\/sub><sub>=SSN<\/sub> Employees<\/li>\r\n<\/ul>\r\n<p class=\"import-Normal\">This would create a long tuple. We can remove the unwanted columns by using projection:<\/p>\r\n\r\n<ul>\r\n \t<li>Result \u2190\u03c0<sub>DepartmentName<\/sub><sub>, LastName, <\/sub><sub>FirstName<\/sub>(DepartmentManager)<\/li>\r\n<\/ul>\r\n<p class=\"import-Normal\">If the Departments table used \u201cSSN\u201d instead of \u201cManagerSSN,\u201d then the line would appear as<\/p>\r\n\r\n<ul>\r\n \t<li>DepartmentManager \u2190Departments \u22c8 <sub>Departments.SSN<\/sub><sub>=<\/sub><sub>Employees.SSN<\/sub>Employees<\/li>\r\n<\/ul>\r\n<p class=\"import-Normal\">Notice the table name, the period (the \u201cdot\u201d), and the field or column name.<\/p>\r\n<p class=\"import-Normal\">According to Thomas Connoly and Carolyn Begg, there are five types of join operations<\/p>\r\n\r\n<ul>\r\n \t<li>Theta join<\/li>\r\n \t<li>Equijoin<\/li>\r\n \t<li>Natural join<\/li>\r\n \t<li>Outer join<\/li>\r\n \t<li>Semijoin<\/li>\r\n<\/ul>\r\n<p class=\"import-Normal\">An inner join will return rows from two tables that satisfies a given condition. This is the most widely used join operation. An inner join can be divided into three sub types:<\/p>\r\n\r\n<ul>\r\n \t<li>Theta join<\/li>\r\n \t<li>Equijoin<sup class=\"import-FootnoteReference\"><a id=\"sdfootnote5anc\" href=\"#sdfootnote5sym\">5<\/a><\/sup><\/li>\r\n \t<li>Natural join<\/li>\r\n<\/ul>\r\n<h4>Theta Join<\/h4>\r\n<p class=\"import-Normal\">A <em>theta <\/em><em>join<\/em> pulls from two tables based on a condition represented by the Greek letter theta (<strong>\u03b8<\/strong>). <strong>\u03b8<\/strong> could be any one of the comparison operators. The general form is:<\/p>\r\n\r\n<table>\r\n<tbody>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\" style=\"text-align: center\"><strong>Formal Form<\/strong><\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\" style=\"text-align: center\"><strong>SQL Form<\/strong><\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\" style=\"margin-left: 9pt\">R \u22c8<sub>\u03b8<\/sub> S<sup class=\"import-FootnoteReference\"><a id=\"sdfootnote6anc\" href=\"#sdfootnote6sym\">6<\/a><\/sup><\/p>\r\n<p class=\"import-Normal\"><\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">SELECT &lt;column names&gt;<\/p>\r\n<p class=\"import-Normal\">FROM &lt;first table name&gt;<\/p>\r\n<p class=\"import-Normal\">INNER JOIN &lt;second table name&gt; ON &lt;first table name column&gt; = &lt;second table name column&gt;<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr>\r\n<td><\/td>\r\n<td><\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n<p class=\"import-Normal\">Figure 10.13 The formal form and the SQL form of a theta (<strong>\u03b8<\/strong><strong>)<\/strong> join.<\/p>\r\n<p class=\"import-Normal\">To understand theta joins better, consider the following example:<\/p>\r\n\r\n<table>\r\n<tbody>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\" colspan=\"2\">\r\n<p class=\"import-Normal\" style=\"text-align: center\">TableA<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"background-color: #d9d9d9;border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\"><\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\" colspan=\"2\">\r\n<p class=\"import-Normal\" style=\"text-align: center\">TableB<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Column1<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Column2<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"background-color: #d9d9d9;border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\"><\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Column1<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Column2<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">1<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">1<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"background-color: #d9d9d9;border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\"><\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">1<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">1<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">1<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">2<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"background-color: #d9d9d9;border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\"><\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">1<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">3<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr>\r\n<td><\/td>\r\n<td><\/td>\r\n<td><\/td>\r\n<td><\/td>\r\n<td><\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n<p class=\"import-Normal\">Figure 10.14 The theta (<strong>\u03b8<\/strong><strong>) <\/strong>join example with two tables. Adapted from Fiona Brown\u2019s example. (Corrected to conform with the Third Edition Style Guide.) Source: https:\/\/www.guru99.com\/joins-sql-left-right.html<\/p>\r\n<p class=\"import-Normal\">We will take R \u22c8<sub>\u03b8<\/sub> S and rewrite it as:<\/p>\r\n<p class=\"import-Normal\" style=\"margin-left: 36pt\">R \u22c8 <sub>R.Column<\/sub><sub>2 &gt; S.Column2<\/sub> (S)<sup class=\"import-FootnoteReference\"><a id=\"sdfootnote7anc\" href=\"#sdfootnote7sym\">7<\/a><\/sup><\/p>\r\n<p class=\"import-Normal\">The output would be<sup class=\"import-FootnoteReference\"><a id=\"sdfootnote8anc\" href=\"#sdfootnote8sym\">8<\/a><\/sup><\/p>\r\n\r\n<table>\r\n<tbody>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\" colspan=\"2\">\r\n<p class=\"import-Normal\">R \u22c8 R.Column2 &gt; S.Column2 (S)<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Column1<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Column2<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">1<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">2<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr>\r\n<td><\/td>\r\n<td><\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n<p class=\"import-Normal\">Figure 10.15 The theta (<strong>\u03b8<\/strong><strong>) <\/strong>join example output table. Adapted from Fiona Brown\u2019s example. (Corrected to conform with the Third Edition Style Guide.) Source: https:\/\/www.guru99.com\/joins-sql-left-right.html<\/p>\r\n<p class=\"import-Normal\">This example is very simple and is a bit misleading. In a theta join (and in the equijoin), both columns that are mentioned in the conditional clause would appear in the output.<\/p>\r\n\r\n<h4>Equijoin<\/h4>\r\n<p class=\"import-Normal\">An <em>equijoin<\/em> is like a theta join in that the equijoin operation pulls from two tables based on a condition represented by the Greek letter theta (<strong>\u03b8<\/strong>). But <strong>\u03b8<\/strong> is the equal symbol (=). We will use the previous example to illustrate the equijoin.<\/p>\r\n<p class=\"import-Normal\" style=\"margin-left: 36pt\">R \u22c8 <sub>R.Column<\/sub><sub>2 = S.Column2<\/sub> (S)<\/p>\r\n<p class=\"import-Normal\">The output would be<\/p>\r\n\r\n<table>\r\n<tbody>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\" colspan=\"2\">\r\n<p class=\"import-Normal\">R\u22c8R.Column2 = S.Column2 (S)<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Column1<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Column2<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">1<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">1<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr>\r\n<td><\/td>\r\n<td><\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n<p class=\"import-Normal\">Figure 10.16 The equijoin example output table. Adapted from Fiona Brown\u2019s example. (Corrected to conform with the Third Edition Style Guide.) Source: https:\/\/www.guru99.com\/joins-sql-left-right.html<\/p>\r\n<p class=\"import-Normal\">Equijoin is not a SQL key word. The WHERE clause contains the equal symbol.<\/p>\r\n\r\n<h4>Natural Join<\/h4>\r\n<p class=\"import-Normal\">A <em>natural <\/em><em>join<\/em> is like a theta join that pulls from two tables, but the extra column is not included in the output and the ON key word is not used. So in Figure 10.13, there would be no theta expression and there would be no ON clause.<\/p>\r\n<p class=\"import-Normal\">Recall that in the union operation, the number of attributes must be the same and the domain types need to be the same. For the natural join, there is the additional requirement that the two tables share at least one common attribute. A natural join will match the common column values and eliminate any duplications. We will use a different example to illustrate a natural join.<\/p>\r\n\r\n<table>\r\n<tbody>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\" colspan=\"2\">\r\n<p class=\"import-Normal\" style=\"text-align: center\">Squares<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"background-color: #d9d9d9;border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\"><\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\" colspan=\"2\">\r\n<p class=\"import-Normal\" style=\"text-align: center\">Cubes<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Number<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Square<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"background-color: #d9d9d9;border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\"><\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Number<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Cube<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">2<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">4<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"background-color: #d9d9d9;border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\"><\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">2<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">8<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">3<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">9<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"background-color: #d9d9d9;border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\"><\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">3<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">18<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr>\r\n<td><\/td>\r\n<td><\/td>\r\n<td><\/td>\r\n<td><\/td>\r\n<td><\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n<p class=\"import-Normal\">Figure 10.17 The natural join example tables. Adapted from Fiona Brown\u2019s example. (Corrected to conform with the Third Edition Style Guide.) Source: https:\/\/www.guru99.com\/joins-sql-left-right.html<\/p>\r\n<p class=\"import-Normal\">We would write the natural join as<\/p>\r\n\r\n<table>\r\n<tbody>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\" style=\"text-align: center\"><strong>Formal Expression<\/strong><\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\" style=\"text-align: center\"><strong>SQL Expression<\/strong><\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\" style=\"margin-left: 13.5pt\">Squares \u22c8 Cubes<\/p>\r\n<p class=\"import-Normal\"><\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">SELECT *<\/p>\r\n<p class=\"import-Normal\">FROM Squares<\/p>\r\n<p class=\"import-Normal\">NATUAL JOIN Cubes;<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr>\r\n<td><\/td>\r\n<td><\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n<p class=\"import-Normal\">Figure 10.18 The formal form and the SQL form of the natural join for Figure 10.17.<\/p>\r\n<p class=\"import-Normal\">The output would be<\/p>\r\n\r\n<table>\r\n<tbody>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\" colspan=\"3\">\r\n<p class=\"import-Normal\">Squares \u22c8 Cubes<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Number<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Square<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Cube<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">2<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">4<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">8<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">3<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">9<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">18<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr>\r\n<td><\/td>\r\n<td><\/td>\r\n<td><\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n<p class=\"import-Normal\">Figure 10.19 The example output table for the natural join. Adapted from Fiona Brown\u2019s example. (Corrected to conform with the Third Edition Style Guide.) Source: https:\/\/www.guru99.com\/joins-sql-left-right.html<\/p>\r\n\r\n<h4>Outer Joins<\/h4>\r\n<p class=\"import-Normal\">An <em>outer <\/em><em>join<\/em> will return rows from two tables even if there are no matches in one of the tables. An outer join can be divided into three sub types:<\/p>\r\n\r\n<ul>\r\n \t<li>Left outer join <strong>(<\/strong><strong>R<\/strong> <strong>\u27d5<\/strong><strong> S<\/strong><strong>)<\/strong><sup class=\"import-FootnoteReference\"><strong><a id=\"sdfootnote9anc\" href=\"#sdfootnote9sym\">9<\/a><\/strong><\/sup><\/li>\r\n \t<li>Right outer join <strong>(<\/strong><strong>R<\/strong> <strong>\u27d6<\/strong> <strong>S<\/strong><strong>)<\/strong><sup class=\"import-FootnoteReference\"><strong><a id=\"sdfootnote10anc\" href=\"#sdfootnote10sym\">10<\/a><\/strong><\/sup><\/li>\r\n \t<li>Full outer join <strong>(<\/strong><strong>R<\/strong> <strong>\u27d7<\/strong> <strong>S<\/strong><strong>)<\/strong><sup class=\"import-FootnoteReference\"><strong><a id=\"sdfootnote11anc\" href=\"#sdfootnote11sym\">11<\/a><\/strong><\/sup><\/li>\r\n<\/ul>\r\n<p class=\"import-Normal\">The outer join is a join in which the tuples from one relation are included even though there is no match in the second relation.<\/p>\r\n\r\n<h4>Left Outer Join<\/h4>\r\n<p class=\"import-Normal\">For the left outer join, you could imagine that the main table is on the \u201cleft\u201d and the second table is on the \u201cright.\u201d Figure 10.20 uses Venn diagrams to illustrate this operation:<\/p>\r\n<p class=\"import-Normal\"><img src=\"https:\/\/pressbooks.bccampus.ca\/nelson\/wp-content\/uploads\/sites\/2211\/2025\/01\/image2-4.png\" alt=\"image\" width=\"539.866666666667px\" height=\"143.466666666667px\" \/><\/p>\r\n<p class=\"import-Normal\">Figure 10.20 Venn diagrams illustrating a left outer join. Source of image: https:\/\/www.guru99.com\/joins-sql-left-right.html<\/p>\r\n<p class=\"import-Normal\">To see this from a different viewpoint, we will take the table from Figure 10.17 and add another row.<\/p>\r\n\r\n<table>\r\n<tbody>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\" colspan=\"2\">\r\n<p class=\"import-Normal\" style=\"text-align: center\">Squares<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"background-color: #d9d9d9;border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\"><\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\" colspan=\"2\">\r\n<p class=\"import-Normal\" style=\"text-align: center\">Cubes<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Number<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Square<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"background-color: #d9d9d9;border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\"><\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Number<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Cube<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">2<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">4<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"background-color: #d9d9d9;border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\"><\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">2<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">8<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">3<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">9<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"background-color: #d9d9d9;border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\"><\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">3<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">18<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">4<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">16<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"background-color: #d9d9d9;border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\"><\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">5<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">75<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr>\r\n<td><\/td>\r\n<td><\/td>\r\n<td><\/td>\r\n<td><\/td>\r\n<td><\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n<p class=\"import-Normal\">Figure 10.21 The source tables for the outer joins. Adapted from Fiona Brown\u2019s example. (Corrected to conform with the Third Edition Style Guide.) Source: https:\/\/www.guru99.com\/joins-sql-left-right.html<\/p>\r\n<p class=\"import-Normal\">We would write the left outer join as<\/p>\r\n\r\n<table>\r\n<tbody>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\" style=\"text-align: center\"><strong>Formal Expression<\/strong><\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\" style=\"text-align: center\"><strong>SQL Expression<\/strong><\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\" style=\"margin-left: 13.5pt\">Squares <strong>\u27d5<\/strong> Cubes<\/p>\r\n<p class=\"import-Normal\"><\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">SELECT &lt;column names&gt;<\/p>\r\n<p class=\"import-Normal\">FROM Squares<\/p>\r\n<p class=\"import-Normal\">LEFT OUTER<sup class=\"import-FootnoteReference\"><a id=\"sdfootnote12anc\" href=\"#sdfootnote12sym\">12<\/a><\/sup> JOIN Cubes ON Squares.Number = Cubes.Number<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr>\r\n<td><\/td>\r\n<td><\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n<p class=\"import-Normal\">Figure 10.22 The formal form and the SQL form of the left outer join for Figure 10.21.<\/p>\r\n<p class=\"import-Normal\">The output would be<\/p>\r\n\r\n<table>\r\n<tbody>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\" colspan=\"3\">\r\n<p class=\"import-Normal\">Squares <strong>\u27d5<\/strong> Cubes<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Number<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Square<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Cube<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">2<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">4<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">8<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">3<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">9<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">18<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">4<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">16<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">NULL<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr>\r\n<td><\/td>\r\n<td><\/td>\r\n<td><\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n<p class=\"import-Normal\">Figure 10.23 The example output table for the left outer join. Adapted from Fiona Brown\u2019s example. (Corrected to conform with the Third Edition Style Guide.) Source: https:\/\/www.guru99.com\/joins-sql-left-right.html<\/p>\r\n<p class=\"import-Normal\">Again, all of the Squares table rows are included in the output plus any matching rows from the Cubes table rows. Any \u201cmissing\u201d rows in this table are noted as NULLs.<\/p>\r\n<p class=\"import-Normal\">If you only want the columns from the left table, then you would use the <em>semijoin<\/em>.<\/p>\r\n\r\n<h4>Right Outer Join<\/h4>\r\n<p class=\"import-Normal\">For the right outer join, you could imagine that the main table is on the \u201cright\u201d and the second table is on the \u201cleft.\u201d Figure 10.24 uses Venn diagrams to illustrate this operation:<\/p>\r\n<p class=\"import-Normal\"><img src=\"https:\/\/pressbooks.bccampus.ca\/nelson\/wp-content\/uploads\/sites\/2211\/2025\/01\/image3-4.png\" alt=\"image\" width=\"542.133333333333px\" height=\"138.933333333333px\" \/><\/p>\r\n<p class=\"import-Normal\">Figure 10.24 Venn diagrams illustrating a right outer join. Source of image: https:\/\/www.guru99.com\/joins-sql-left-right.html<\/p>\r\n<p class=\"import-Normal\">To see this from a different viewpoint, we will take the table from Figure 10.17.<\/p>\r\n<p class=\"import-Normal\">We would write the right outer join as<\/p>\r\n\r\n<table>\r\n<tbody>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\" style=\"text-align: center\"><strong>Formal Expression<\/strong><\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\" style=\"text-align: center\"><strong>SQL Expression<\/strong><\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\" style=\"margin-left: 13.5pt\">Squares <strong>\u27d6<\/strong> Cubes<\/p>\r\n<p class=\"import-Normal\"><\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">SELECT &lt;column names&gt;<\/p>\r\n<p class=\"import-Normal\">FROM Cubes<\/p>\r\n<p class=\"import-Normal\">RIGHT OUTER<sup class=\"import-FootnoteReference\"><a id=\"sdfootnote13anc\" href=\"#sdfootnote13sym\">13<\/a><\/sup> JOIN Squares ON Cubes.Number = Squares.Number<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr>\r\n<td><\/td>\r\n<td><\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n<p class=\"import-Normal\">Figure 10.25 The formal form and the SQL form of the right outer join for Figure 10.17.<\/p>\r\n<p class=\"import-Normal\">The output would be<\/p>\r\n\r\n<table>\r\n<tbody>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\" colspan=\"3\">\r\n<p class=\"import-Normal\">Squares <strong>\u27d6<\/strong> Cubes<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Number<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Cube<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Square<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">2<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">8<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">4<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">3<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">18<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">9<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">5<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">75<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">NULL<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr>\r\n<td><\/td>\r\n<td><\/td>\r\n<td><\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n<p class=\"import-Normal\">Figure 10.26 The example output table for the right outer join. Adapted from Fiona Brown\u2019s example. (Corrected to conform with the Third Edition Style Guide.) Source: https:\/\/www.guru99.com\/joins-sql-left-right.html<\/p>\r\n<p class=\"import-Normal\">Again, all of the Cubes table rows are included in the output plus any matching rows from the Squares table rows. Any \u201cmissing\u201d rows in this table are noted as NULLs.<\/p>\r\n\r\n<h4>Full Outer Join<\/h4>\r\n<p class=\"import-Normal\">For the full outer join, you could imagine that there are two main tables and we are including all tuples or rows in the output. It seems that we are ignoring the matching condition clause. That is not true. This helps to determine where the NULL entries would appear. Figure 10.27 uses Venn diagrams to illustrate this operation:<\/p>\r\n<p class=\"import-Normal\"><img src=\"https:\/\/pressbooks.bccampus.ca\/nelson\/wp-content\/uploads\/sites\/2211\/2025\/01\/image4-1.jpeg\" alt=\"image\" width=\"311.733333333333px\" height=\"199.933333333333px\" \/><\/p>\r\n<p class=\"import-Normal\">Figure 10.27 Venn diagrams illustrating a full outer join. Source of image: https:\/\/www.w3schools.com\/sql\/sql_join_full.asp<sup class=\"import-FootnoteReference\"><a id=\"sdfootnote14anc\" href=\"#sdfootnote14sym\">14<\/a><\/sup><\/p>\r\n<p class=\"import-Normal\">To see this from a different viewpoint, we will take the table from Figure 10.17.<\/p>\r\n<p class=\"import-Normal\">We would write the full outer join as<\/p>\r\n\r\n<table>\r\n<tbody>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\" style=\"text-align: center\"><strong>Formal Expression<\/strong><\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\" style=\"text-align: center\"><strong>SQL Expression<\/strong><\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\" style=\"margin-left: 13.5pt\">Squares <strong>\u27d7<\/strong> Cubes<\/p>\r\n<p class=\"import-Normal\"><\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">SELECT &lt;column names&gt;<\/p>\r\n<p class=\"import-Normal\">FROM Squares<\/p>\r\n<p class=\"import-Normal\">FULL OUTER<sup class=\"import-FootnoteReference\"><a id=\"sdfootnote15anc\" href=\"#sdfootnote15sym\">15<\/a><\/sup> JOIN Cubes ON Squares.Number = Cubes.Number<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr>\r\n<td><\/td>\r\n<td><\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n<p class=\"import-Normal\">Figure 10.28 The formal form and the SQL form of the right outer join for Figure 10.17.<\/p>\r\n<p class=\"import-Normal\">The output would be<\/p>\r\n\r\n<table>\r\n<tbody>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\" colspan=\"3\">\r\n<p class=\"import-Normal\">Squares <strong>\u27d7<\/strong> Cubes<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Number<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Square<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Cube<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">2<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">4<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">8<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">3<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">9<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">18<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">4<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">16<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">NULL<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">5<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">NULL<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">75<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr>\r\n<td><\/td>\r\n<td><\/td>\r\n<td><\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n<p class=\"import-Normal\">Figure 10.29 The example output table for the full outer join. Adapted from Fiona Brown\u2019s example. (Corrected to conform with the Third Edition Style Guide.) Source: https:\/\/www.guru99.com\/joins-sql-left-right.html<\/p>\r\n<p class=\"import-Normal\">Again, all of the rows from both tables are included in the output with \u201cmissing\u201d fields filled in as NULLs.<\/p>\r\n\r\n<h4>Other Joins<\/h4>\r\n<p class=\"import-Normal\">The inner join is the most widely used join operation and can be regarded as the default join type. We have explored the theta join, the natural join, and equijoin. These are \u201cshort cut\u201d ways of expressing a desired form of the inner join.<\/p>\r\n<p class=\"import-Normal\">Outer joins preserve rows with incomplete data. For example, we could see in the output both customers that have ordered something and that have not ordered anything recently.<\/p>\r\n<p class=\"import-Normal\">Some databases support the <em>self join<\/em>. This is when one table is treated as two tables. W3 schools website has an example where the user is looking for customers that are from the same city. The syntax is a bit odd. See <a class=\"rId12\" href=\"https:\/\/www.w3schools.com\/sql\/sql_join_self.asp\"><span class=\"import-Hyperlink\">https:\/\/www.w3schools.com\/sql\/sql_join_self.asp<\/span><\/a> for this example<\/p>\r\n<p class=\"import-Normal\">The <em>anti <\/em><em>join<\/em> will return the rows that semi join had rejected. See <a class=\"rId13\" href=\"https:\/\/blog.dailydoseofds.com\/p\/what-are-semi-anti-and-natural-joins\"><span class=\"import-Hyperlink\">https:\/\/blog.dailydoseofds.com\/p\/what-are-semi-anti-and-natural-joins<\/span><\/a> for more information.<\/p>\r\n<p class=\"import-Normal\">Figure 10.30 shows seven of the possible joins.<\/p>\r\n<p class=\"import-Normal\"><img src=\"https:\/\/pressbooks.bccampus.ca\/nelson\/wp-content\/uploads\/sites\/2211\/2025\/01\/image5-6.png\" alt=\"image\" width=\"624px\" height=\"440.133333333333px\" \/><\/p>\r\n<p class=\"import-Normal\">Figure 10.30 Seven join SQL commands with Venn diagrams. Source of image: https:\/\/www.techdoge.in\/2017\/10\/learn-sql-MySql-what-is-join-and-how-to-use-them.html<\/p>\r\n\r\n<h3>Binary Relational Operation: Division<\/h3>\r\n<p class=\"import-Normal\">The<em> division<\/em> operation is defined to be a relation over the attributes that consists of the set of tuples from R that match the combination of every tuple in S. This abstract definition may be hard to understand. The following are example use cases where the division operator would be useful:<\/p>\r\n\r\n<ul>\r\n \t<li>Find suppliers that can provide all parts.<\/li>\r\n \t<li>Find all employees who have worked on all projects controlled by one department.<\/li>\r\n \t<li>Find the topic that is taught in all courses.<\/li>\r\n<\/ul>\r\n<p class=\"import-Normal\">Do not confuse regular algebra subtraction and division. For example:<\/p>\r\n<p class=\"import-Normal\">10 \/ 2 is similar to 10 \u2013 2 becomes 8 -2 becomes 6 \u2013 2 becomes 4 \u2013 2 becomes 2 \u2013 2, which is subtracting the number 2 five times.<\/p>\r\n<p class=\"import-Normal\">In relational algebra subtraction, we are looking for all tuples that are present in the first table, but are not in the second table. In relational algebra division, we are looking for something in the first table that has a relationship with every entity in the second table.<\/p>\r\n<p class=\"import-Normal\">Imagine that you have come to the British Columbia government website that has a list of post-secondary institutions (<a class=\"rId15\" href=\"https:\/\/www2.gov.bc.ca\/gov\/content\/education-training\/post-secondary-education\/find-a-program-or-institution\/find-an-institution\"><span class=\"import-Hyperlink\">https:\/\/www2.gov.bc.ca\/gov\/content\/education-training\/post-secondary-education\/find-a-program-or-institution\/find-an-institution<\/span><\/a>). Behind the page, imagine that there are two database tables. One contains all of the possible academic majors available in British Columbia. The second table contains rows that have the institution\u2019s name and the available academic majors. Figure 10.31 shows an extract from these imaginary database tables.<\/p>\r\n\r\n<table>\r\n<tbody>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\" style=\"text-align: center\">MajorsInBC<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"background-color: #d9d9d9;border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\"><\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\" colspan=\"2\">\r\n<p class=\"import-Normal\" style=\"text-align: center\">InstitutionsAndMajors<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">AvailableMajors<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"background-color: #d9d9d9;border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\"><\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Institution<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Majors<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Computer Application Training<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"background-color: #d9d9d9;border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\"><\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">British Columbia Institute of Technology<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Computer Application Training<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Computer Hardware<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"background-color: #d9d9d9;border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\"><\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">British Columbia Institute of Technology<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Computer Hardware<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Forensic Computing<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"background-color: #d9d9d9;border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\"><\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">British Columbia Institute of Technology<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Forensic Computing<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Networking and Security<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"background-color: #d9d9d9;border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\"><\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">British Columbia Institute of Technology<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Networking and Security<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Software Development<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"background-color: #d9d9d9;border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\"><\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">British Columbia Institute of Technology<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Software Development<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Web Technologies<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"background-color: #d9d9d9;border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\"><\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">British Columbia Institute of Technology<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Web Technologies<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Computing Studies and Information Systems<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"background-color: #d9d9d9;border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\"><\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Camosun College<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Marketing<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Web and Mobile Computing<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"background-color: #d9d9d9;border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\"><\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Camosun College<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Sport Management<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Fine and Applied Arts<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"background-color: #d9d9d9;border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\"><\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Capilano University<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Fine and Applied Arts<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Global and Community Studies<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"background-color: #d9d9d9;border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\"><\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Capilano University<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Global and Community Studies<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">General Studies<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"background-color: #d9d9d9;border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\"><\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Coast Mountain College<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">General Studies<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Marketing<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"background-color: #d9d9d9;border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\"><\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Coast Mountain College<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Environmental Geoscience Specialization<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Sport Management<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"background-color: #d9d9d9;border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\"><\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Douglas College<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Computing Studies and Information Systems<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Environmental Geoscience Specialization<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"background-color: #d9d9d9;border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\"><\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Douglas College<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Web and Mobile Computing<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr>\r\n<td><\/td>\r\n<td><\/td>\r\n<td><\/td>\r\n<td><\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n<p class=\"import-Normal\">Figure 10.31 Data drawn from the British Columba education website and from several institutions in British Columbia.<\/p>\r\n<p class=\"import-Normal\">Figure 10.31 does not list all 25 higher education institutions in British Columbia. Nor does Figure 10.31 list all of the possible majors the sample institutions or the rest of the higher education institutions. Let\u2019s imagine that you wish to explore all web computing programs.<\/p>\r\n<p class=\"import-Normal\">We could use MajorsInBC \u00f7 InstitutionsAndMajors. The result would be as follows:<\/p>\r\n\r\n<table style=\"width: 478.8pt\">\r\n<tbody>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\" colspan=\"2\">\r\n<p class=\"import-Normal\">InstitutionsAndMajors<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">British Columbia Institute of Technology<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Web Technologies<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Douglas College<\/p>\r\n<\/td>\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\r\n<p class=\"import-Normal\">Web and Mobile Computing<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\" colspan=\"2\">\r\n<p class=\"import-Normal\">=<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\" colspan=\"2\">\r\n<p class=\"import-Normal\">MajorsInBC<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr class=\"TableGrid-R\">\r\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\" colspan=\"2\">\r\n<p class=\"import-Normal\">Web<\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr>\r\n<td><\/td>\r\n<td><\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n<p class=\"import-Normal\">Figure 10.32 Result of finding institutions in British Columbia with a web major.<sup class=\"import-FootnoteReference\"><a id=\"sdfootnote16anc\" href=\"#sdfootnote16sym\">16<\/a><\/sup><\/p>\r\n<p class=\"import-Normal\">This contrived example ignored the fact that \u201cweb technologies\u201d and \u201cweb and mobile computing\u201d are different. The problem with this example is that the second table is not normalized.<\/p>\r\n<p class=\"import-Normal\">Some textbooks and some websites do not address this topic. Most SQL implementations do not support the division operation. So how would division be done in modern relational DBMS?<\/p>\r\n<p class=\"import-Normal\">The Geeks for Geeks article listed the following ways to implement relational division in SQL:<\/p>\r\n\r\n<ul>\r\n \t<li>Method 1: Use cross join and EXCEPT<\/li>\r\n \t<li>Method 2: Use correlated subquery and NOT EXISTS<\/li>\r\n<\/ul>\r\n<p class=\"import-Normal\">As division can be rendered as a series of subtraction steps, relational algebra can do the same thing:<\/p>\r\n\r\n<ol>\r\n \t<li>Generate all combinations by computing the Cartesian product of all possible y values in S with distinct x values in R.<\/li>\r\n \t<li>Identify the incomplete combinations. Use the subtract relational operator by subtracting R from the combinations in step 1 in order to find x values not associated with every y.<\/li>\r\n \t<li>Subtract the identified x values from all x values to get those associated with every y.<\/li>\r\n<\/ol>\r\n<p class=\"import-Normal\">One final note. It is possible to use the regular division operator in SQL<sup class=\"import-FootnoteReference\"><a id=\"sdfootnote17anc\" href=\"#sdfootnote17sym\">17<\/a><\/sup>. An example might be that you wish to output what would be value of dividing in half the current price of products in a table.<\/p>\r\n<p class=\"import-Normal\" style=\"padding-left: 40px\">SELECT Price, Price \/ 2 AS \u201cHalf Price\u201d<\/p>\r\n<p class=\"import-Normal\" style=\"padding-left: 40px\">FROM Products;<\/p>\r\n<p class=\"import-Normal\">This is not the relational algebra division operator.<\/p>\r\n\r\n<h2>Regular Calculus and Relational Calculus<\/h2>\r\n<p class=\"import-Normal\">Regular calculus is the study of rates of change. Differential calculus is concerned with the rate of change and works with derivatives and differentials. There is great interest in the slope of a line. Integral calculus seeks to find the quantity where the rate of change is known. Integral calculus looks at the space or area under the curve or slope.<\/p>\r\n<p class=\"import-Normal\">Wolfram MathWorld used the word \u201canalysis\u201d as another term for the word \u201ccalculus<sup class=\"import-FootnoteReference\"><a id=\"sdfootnote18anc\" href=\"#sdfootnote18sym\">18<\/a><\/sup>.\u201d Thomas Connoly and Carolyn Begg pointed out that relational calculus is closer to predicate calculus.<\/p>\r\n<p class=\"import-Normal\">A <em>predicate<\/em> is an expression of one or more variables for a certain domain. Consider the following:<\/p>\r\n<p class=\"import-Normal\" style=\"padding-left: 40px\">Douglas College is a public college.<\/p>\r\n<p class=\"import-Normal\">Predicate calculus would make the following statements:<\/p>\r\n\r\n<ul>\r\n \t<li>\u201c\u2026 is a public college\u201d is a predicate and \u201cDouglas College\u201d is the subject.<\/li>\r\n \t<li>Let \u201cDouglas College\u201d be denoted as \u201cx\u201d and \u201c..is a public college\u201d be denoted as Predicate P. Then we can write\r\n<ul>\r\n \t<li>P(x)<\/li>\r\n<\/ul>\r\n<\/li>\r\n<\/ul>\r\n<p class=\"import-Normal\">A predicate must have at least one object that is associated with the predicate. \u201cDouglas College\u201d is the required object.<\/p>\r\n<p class=\"import-Normal\">We will not go any deeper on the topic of predicate calculus. You can learn more about this topic by visiting <a class=\"rId16\" href=\"https:\/\/www.tutorialspoint.com\/the-predicate-calculus\"><span class=\"import-Hyperlink\">https:\/\/www.tutorialspoint.com\/the-predicate-calculus<\/span><\/a><\/p>\r\n<p class=\"import-Normal\"><em>Relational calculus<\/em> specifies <strong>what <\/strong>is to be retrieved whereas relational algebra states <strong>how<\/strong> to obtain the results. In relational calculus, we work with tuple relational calculus and with domain relational calculus.<\/p>\r\n\r\n<h3>Tuple Relational Calculus<\/h3>\r\n<p class=\"import-Normal\">In <em>tuple relational calculus<\/em>, we wish to obtain those tuples that are true for a certain predicate. Using the above predicate example (\u201cDouglas College is a public college.\u201d), we could use the following shorthand:<\/p>\r\n<p class=\"import-Normal\" style=\"padding-left: 40px\">PublicCollege(S)<\/p>\r\n<p class=\"import-Normal\" style=\"padding-left: 40px\">Where the tuple variable S would be the range of permitted values.<\/p>\r\n<p class=\"import-Normal\">So we could have the following query:<\/p>\r\n<p class=\"import-Normal\" style=\"padding-left: 40px\">Find the set of all tuples S such that F(S) is true<\/p>\r\n<p class=\"import-Normal\" style=\"padding-left: 80px\">{S | F(S)|<\/p>\r\n<p class=\"import-Normal\">Our S could be all public colleges in British Columbia, or in Canada, or in North America, or in the world. In this example, S would not contain high schools or people\u2019s names or animal names.<\/p>\r\n<p class=\"import-Normal\">In the above shorthand expression, the letter \u201cF\u201d is called a formula or in pure mathematical logic, a well-formed formula or wff.<\/p>\r\n<p class=\"import-Normal\">Imagine that we are working with a database table with the names of Staffers and that contains the following columns:<\/p>\r\n\r\n<ul>\r\n \t<li>ID<\/li>\r\n \t<li>FirstName<\/li>\r\n \t<li>LastName<\/li>\r\n \t<li>Position<\/li>\r\n \t<li>Gender<\/li>\r\n \t<li>DoB<\/li>\r\n \t<li>Salary<\/li>\r\n \t<li>BranchNumber<\/li>\r\n<\/ul>\r\n<p class=\"import-Normal\">We wish to express in relational calculus the following:<\/p>\r\n<p class=\"import-Normal\" style=\"margin-left: 36pt\">Find the ID, FirstName, LastName, Position, Gender, DoB, Salary, and BranchNumber for individuals earning more than $10,000.<\/p>\r\n<p class=\"import-Normal\">This query would appear as follows:<\/p>\r\n<p class=\"import-Normal\" style=\"padding-left: 40px\">{S | Staffers(s) <strong>\u2227<\/strong><sup class=\"import-FootnoteReference\"><strong><a id=\"sdfootnote19anc\" href=\"#sdfootnote19sym\">19<\/a><\/strong><\/sup> S.Salary &gt; 10000}<\/p>\r\n<p class=\"import-Normal\">The letter \u201cS\u201d between the left curved brace and the pipe symbol means all columns. The <strong>\u2227<\/strong> is the logical conjunction and may be read as \u201cand.\u201d This is the Boolean AND operator. A tuple is collected if the row exists with a Salary greater than $10,000. In this example, we are assuming that the Staffers table has only columns for ID, FirstName, LastName, Position, Gender, DoB, Salary, and BranchNumber. If we wish to select a subset such as the Salary column, then we would need to modify the last expression as follows:<\/p>\r\n<p class=\"import-Normal\" style=\"margin-left: 36pt\">{S.Salary | Staffers(s) <strong>\u2227<\/strong> S.Salary &gt; 10000}<\/p>\r\n<p class=\"import-Normal\">Predicate calculus uses two quantifiers. Relational calculus uses these same two quantifiers.<\/p>\r\n\r\n<ul>\r\n \t<li>The <em>existential quantifier<\/em> <a class=\"rId17\" title=\"\u2203\" href=\"https:\/\/en.wikipedia.org\/wiki\/%E2%88%83\"><strong class=\"import-Hyperlink\">\u2203<\/strong><\/a><sup class=\"import-FootnoteReference\"><strong><a id=\"sdfootnote20anc\" href=\"#sdfootnote20sym\">20<\/a><\/strong><\/sup> means \u201cthere exists\u201d. At least one instance or tuple is true for the statement.<\/li>\r\n \t<li>The <em>universal quantifier<\/em> <a class=\"rId18\" title=\"\u2200\" href=\"https:\/\/en.wikipedia.org\/wiki\/%E2%88%80\"><span class=\"import-Hyperlink\">\u2200<\/span><\/a><sup class=\"import-FootnoteReference\"><a id=\"sdfootnote21anc\" href=\"#sdfootnote21sym\">21<\/a><\/sup> means \u201cfor all.\u201d All tuples must be true for the statement.<\/li>\r\n<\/ul>\r\n<p class=\"import-Normal\">Let\u2019s use Douglas College as our example and express two statements in relational calculus:<\/p>\r\n\r\n<ul>\r\n \t<li>There exists a Course (C) tuple that has the same ID (CourseID) as the CourseID of the current Student tuple, S, and is located in New Westminster.\r\n<ul>\r\n \t<li>Student(S) <strong>\u2227<\/strong> (<a class=\"rId19\" title=\"\u2203\" href=\"https:\/\/en.wikipedia.org\/wiki\/%E2%88%83\"><strong class=\"import-Hyperlink\">\u2203<\/strong><\/a>C) (Course(C) <strong>\u2227<\/strong> (C.ID = S.CourseID) <strong>\u2227<\/strong> C.City = \u201cNew Westminster\u201d<\/li>\r\n<\/ul>\r\n<\/li>\r\n \t<li>For all Computing Studies and Information Systems courses (C), the city is New Westminster.\r\n<ul>\r\n \t<li>(<a class=\"rId20\" title=\"\u2200\" href=\"https:\/\/en.wikipedia.org\/wiki\/%E2%88%80\"><span class=\"import-Hyperlink\">\u2200<\/span><\/a>C) (C.City = \u201cNew Westminster\u201d)<\/li>\r\n<\/ul>\r\n<\/li>\r\n<\/ul>\r\n<p class=\"import-Normal\">Negations could be used. So the last expression could be written as<\/p>\r\n\r\n<ul>\r\n \t<li style=\"list-style-type: none\">\r\n<ul>\r\n \t<li>(<a class=\"rId21\" title=\"\u2200\" href=\"https:\/\/en.wikipedia.org\/wiki\/%E2%88%80\"><span class=\"import-Hyperlink\">\u2200<\/span><\/a>C) (C.City \u2260 \u201cCoquitlam<sup class=\"import-FootnoteReference\"><a id=\"sdfootnote22anc\" href=\"#sdfootnote22sym\">22<\/a><\/sup>\u201d)<\/li>\r\n<\/ul>\r\n<\/li>\r\n<\/ul>\r\n<p class=\"import-Normal\">Recall that the intersection binary relational operator could be rewritten as a series of union and set differences, so relational calculus statements could be expressed in other ways. De Morgan\u2019s laws can be used. The following is another version of the last expression:<\/p>\r\n\r\n<ul>\r\n \t<li>~(<a class=\"rId22\" title=\"\u2203\" href=\"https:\/\/en.wikipedia.org\/wiki\/%E2%88%83\"><strong class=\"import-Hyperlink\">\u2203<\/strong><\/a>C) (C.City = \u201cCoquitlam\u201d)<\/li>\r\n<\/ul>\r\n<p class=\"import-Normal\">Recall that in a Boolean environment, you could negate an AND statement by negating each element and changing the AND to become an OR:<\/p>\r\n<p class=\"import-Normal\" style=\"padding-left: 40px\">~(A AND B) is the same thing as ~ A OR ~B<sup class=\"import-FootnoteReference\"><a id=\"sdfootnote23anc\" href=\"#sdfootnote23sym\">23<\/a><\/sup><\/p>\r\n<p class=\"import-Normal\">This behavior is true in relational calculus. Notice the change in from <a class=\"rId23\" title=\"\u2200\" href=\"https:\/\/en.wikipedia.org\/wiki\/%E2%88%80\"><span class=\"import-Hyperlink\">\u2200<\/span><\/a> to <a class=\"rId24\" title=\"\u2203\" href=\"https:\/\/en.wikipedia.org\/wiki\/%E2%88%83\"><strong class=\"import-Hyperlink\">\u2203<\/strong><\/a>.<\/p>\r\n<p class=\"import-Normal\">You need to be careful, because you could create an unsafe expression. Look at the following:<\/p>\r\n\r\n<ul>\r\n \t<li>The set of all tuples that are not in the Student relation:\r\n<ul>\r\n \t<li>{S | ~ Student(S)}<\/li>\r\n<\/ul>\r\n<\/li>\r\n<\/ul>\r\n<p class=\"import-Normal\">This is <em>unsafe<\/em>, because this would generate a huge number of tuples. To avoid this, we need to add a restriction that all values that appear in the result must be values in the <em>domain<\/em> of the expression E, donated as dom (E). Or to put it differently, the domain of E is the set of all values that appear explicitly in E or that appear in or more relations whose names appear in E. In the last relational calculus example, the domain of the expression is the set of all values that appear in the Student relation. So an expression is <em>safe<\/em> if all values that appear in the result are values drawn from the domain of the expression. All of the previous examples of tuple relational calculus are safe.<\/p>\r\n\r\n<h3>Domain Relational Calculus<\/h3>\r\n<p class=\"import-Normal\"><em>Domain relational calculus<\/em> uses variables, but the variables come the domains of the attributes instead from the tuples of relations. An expression in domain relational calculus has the following general form:<\/p>\r\n<p class=\"import-Normal\" style=\"padding-left: 40px\">{ d<sub>1<\/sub>, d<sub>2<\/sub>, \u2026, d<sub>n<\/sub> | F(d<sub>1<\/sub>, d<sub>2<\/sub>, \u2026, d<sub>m<\/sub>) } m \u2265 n<\/p>\r\n<p class=\"import-Normal\" style=\"padding-left: 80px\">Where d<sub>1<\/sub>, d<sub>2<\/sub>, \u2026, d<sub>n<\/sub><sub> and <\/sub>d<sub>1<\/sub>, d<sub>2<\/sub>, \u2026, d<sub>m <\/sub>represent the domain variables<\/p>\r\n<p class=\"import-Normal\" style=\"padding-left: 80px\">Where F(d<sub>1<\/sub>, d<sub>2<\/sub>, \u2026, d<sub>m<\/sub>) represents a formula composed of atoms and an atom has the one of the following forms:<\/p>\r\n\r\n<ul>\r\n \t<li style=\"list-style-type: none\">\r\n<ul>\r\n \t<li style=\"list-style-type: none\">\r\n<ul>\r\n \t<li>R(d<sub>1<\/sub>, d<sub>2<\/sub>, \u2026, d<sub>n<\/sub>), where R is a relation of degree n and each d<sub>i<\/sub> is a domain variable.<\/li>\r\n \t<li>d<sub>i<\/sub> <strong>\u03b8<\/strong> d<sub>j<\/sub>, where d<sub>i<\/sub> and d<sub>j<\/sub> are domain variables and <strong>\u03b8<\/strong> is one of the comparison operator (&lt;, \u2264, &gt;, \u2265, =, \u2260); the domains d<sub>i<\/sub> and d<sub>j<\/sub> must have members that can be compared by <strong>\u03b8<\/strong><strong>.<\/strong><\/li>\r\n \t<li>d<sub>i<\/sub> <strong>\u03b8<\/strong> c,, where d<sub>i<\/sub> is a domain variable, c is a constant from the domain of d<sub>i<\/sub>, and <strong>\u03b8<\/strong> is one of the comparison operators.<\/li>\r\n<\/ul>\r\n<\/li>\r\n<\/ul>\r\n<\/li>\r\n<\/ul>\r\n<p class=\"import-Normal\">The word \u201catom\u201d is used, because atoms are the building blocks for more complex formulae.<\/p>\r\n<p class=\"import-Normal\">Recall the relational calculus example:<\/p>\r\n<p class=\"import-Normal\" style=\"margin-left: 36pt\">Find the ID, FirstName, LastName, Position, Gender, DoB, Salary, and BranchNumber for individuals earning more than $10,000.<\/p>\r\n<p class=\"import-Normal\">That query appeared as follows:<\/p>\r\n<p class=\"import-Normal\" style=\"padding-left: 40px\">{S | Staffers(s) <strong>\u2227<\/strong> S.Salary &gt; 10000}<\/p>\r\n<p class=\"import-Normal\">To demonstrate how complex a domain relational calculus expression can be, we will add the restriction of finding managers that earn more than $10,000. So this query would appear as follows:<\/p>\r\n<p class=\"import-Normal\" style=\"padding-left: 40px\">{FirstName, LastName | <a class=\"rId25\" title=\"\u2203\" href=\"https:\/\/en.wikipedia.org\/wiki\/%E2%88%83\"><strong class=\"import-Hyperlink\">\u2203<\/strong><\/a>ID, Position, Gender, DoB, Salary, BranchNumber) (Staffers (ID, FirstName, LastName, Position, Gender, DoB, Salary, BranchNumber) <strong>\u2227<\/strong> Position = \u201cManager\u201d <strong>\u2227<\/strong> Salary &gt; 10000)}<\/p>\r\n<p class=\"import-Normal\">The condition (Staffers (ID, FirstName, LastName, Position, Gender, DoB, Salary, BranchNumber) ensures that the domain variables are restricted to the attributes of the same tuple. Since we used this condition, we could use the shortcut of \u201cPosition = Manager\u201d instead of \u201cStaff.Position = \u201cManager.\u201d This approach has an interesting benefit. We do not need to use the existential quantifier <a class=\"rId26\" title=\"\u2203\" href=\"https:\/\/en.wikipedia.org\/wiki\/%E2%88%83\"><strong class=\"import-Hyperlink\">\u2203<\/strong><\/a>. Another benefit is that these queries are safe.<\/p>\r\n<p class=\"import-Normal\">Domain relational calculus was presented for completeness. We will not go any further.<\/p>\r\n\r\n<h3>Recapping Relational Algebra and Relational Calculus<\/h3>\r\n<p class=\"import-Normal\">Relational calculus specifies <strong>what <\/strong>is to be retried whereas relational algebra states <strong>how<\/strong> to obtain the results. For every relational algebra expression, there is an equivalent expression in relational calculus. And for every tuple relational calculus or domain relational calculus expression there is an equivalent relational algebra expression.<\/p>\r\n<p class=\"import-Normal\">We can use the relational algebra to rewrite a query to be more efficient.<\/p>\r\n<p class=\"import-Normal\">Relational algebra and relational calculus can be used to write statements as a common language (a lingua franca) between database developers. Consider the command for obtaining the first three rows from a database table:<\/p>\r\n\r\n<ul>\r\n \t<li>Microsoft: SELECT TOP 3 * FROM Customers;<\/li>\r\n \t<li>MySQL: SELECT * FROM Customers Limit 3;<\/li>\r\n \t<li>Oracle: SELECT * FROM Customers where rownum &lt;= 3;<\/li>\r\n<\/ul>\r\n<p class=\"import-Normal\"><strong>\u00a0<\/strong><\/p>\r\n\r\n<h2>Key Terms<\/h2>\r\n<p class=\"import-Normal\"><strong>anti<\/strong><strong> join<\/strong>: This will return the rows that semi join had rejected.<\/p>\r\n<p class=\"import-Normal\"><strong>atom<\/strong><strong>:<\/strong> This is a building block for more complex formulae in domain relational calculus.<\/p>\r\n<p class=\"import-Normal\"><strong>binary<\/strong><strong>: <\/strong>The operation involves two database tables.<\/p>\r\n<p class=\"import-Normal\"><strong>Cartesian product<\/strong><strong>:<\/strong> This is an operation from set theory. This is also known as \u201ccross product.\u201d If we drop the requirement that a relation must be union compatible, then you could have an output that is larger than either relation. The result is a new element by combining every member tuple from one relation set with every member tuple from the other relation set.<\/p>\r\n<p class=\"import-Normal\"><strong>c<\/strong><strong>ommutative<\/strong><strong>: <\/strong>The sequence of actions could be changed and the answer would still be the same.<\/p>\r\n<p class=\"import-Normal\"><strong>division<\/strong><strong>:<\/strong> This operation is defined to be a relation over the attributes that consists of the set of tuples from R that match the combination of every tuple in S.<\/p>\r\n<p class=\"import-Normal\"><strong>e<\/strong><strong>quijoin:<\/strong> This is like a theta join in that the equijoin operation pulls from two tables based on a condition represented by the Greek letter theta (<strong>\u03b8<\/strong>). But <strong>\u03b8<\/strong> is the equal symbol (=).<\/p>\r\n<p class=\"import-Normal\"><strong>existential quantifier<\/strong> <a class=\"rId27\" title=\"\u2203\" href=\"https:\/\/en.wikipedia.org\/wiki\/%E2%88%83\"><strong class=\"import-Hyperlink\">\u2203<\/strong><\/a><strong>: <\/strong>This means \u201cthere exists\u201d at least one instance or tuple that is true for the statement.<\/p>\r\n<p class=\"import-Normal\"><strong>i<\/strong><strong>ntersection \u2229<\/strong><strong>:<\/strong> This is a set operation that does not have a counterpart in regular algebra. It extracts what is common to two database tables based on a conditional.<\/p>\r\n<p class=\"import-Normal\"><strong>j<\/strong><strong>oin<\/strong> <strong>\u22c8<\/strong><strong>:<\/strong> This is an operation from set theory. A way of pulling from two tables. This was added to the set operators.<\/p>\r\n<p class=\"import-Normal\"><strong>natural join<\/strong><strong>:<\/strong> This is like a theta join that pulls from two tables, but the extra column is not included in the output and the ON key word is not used.<\/p>\r\n<p class=\"import-Normal\"><strong>operands<\/strong><strong>:<\/strong> In regular algebra, these are variables or values used in an expression. In relational algebra, these are relations or variables that represent relations.<\/p>\r\n<p class=\"import-Normal\"><strong>o<\/strong><strong>perators<\/strong><strong>:<\/strong> In regular algebra, these are symbols that denote what will be done to the regular algebra operands. In relational algebra, these are the common actions that we need to do with relations in a database.<\/p>\r\n<p class=\"import-Normal\"><strong>o<\/strong><strong>uter join<\/strong>: This will return rows from two tables even if there are no matches in one of the tables. An outer join can be divided into three sub types:<\/p>\r\n\r\n<ul>\r\n \t<li>Left outer join (R \u27d5 S): Everything from left plus any matching rows on the left with the right table plus nulls for any missing rows.<\/li>\r\n \t<li>Right outer join (R \u27d6 S): Everything from right plus any matching rows on the right with the left table plus nulls for any missing rows<\/li>\r\n \t<li>Full outer join (R \u27d7 S): Everything from both tables plus nulls for any missing fields.<\/li>\r\n<\/ul>\r\n<p class=\"import-Normal\"><strong>predicate<\/strong><strong>: <\/strong>This is an expression of one or more variables for a certain domain. A predicate must have at least one object that is associated with the predicate.<\/p>\r\n<p class=\"import-Normal\"><strong>projection \u03c0<\/strong><strong> (The lower case Greek letter pi): <\/strong>This selects a subset of the available columns. This was added to the set operators.<\/p>\r\n<p class=\"import-Normal\"><strong>relational algebra<\/strong><strong>:<\/strong> This collects instances of relations as input and gives occurrences of relations as outputs. The expressions explain how to execute a query. The expressions are independent of any SQL system.<\/p>\r\n<p class=\"import-Normal\"><strong>relational calculus<\/strong>: This specifies <strong>what <\/strong>is to be retrieved whereas relational algebra states<strong> how<\/strong> to obtain the results. In relational calculus, we work with tuple relational calculus and with domain relational calculus.<\/p>\r\n\r\n<ul>\r\n \t<li>Tuple relational calculus: This seeks to obtain those tuples that are true for a certain predicate. The variables come from the tuples of the relations.<\/li>\r\n \t<li>Domain relational calculus: This uses variables come from the domains of the attributes.<\/li>\r\n<\/ul>\r\n<p class=\"import-Normal\"><strong>r<\/strong><strong>enaming<\/strong> <strong> \u03f8<\/strong><strong> (The lower case Greek letter rho)<\/strong><strong>: <\/strong>This renames the output columns. This was added to the set operators.<\/p>\r\n<p class=\"import-Normal\"><strong>safe<\/strong>: The expression draws upon members of a defined domain.<\/p>\r\n<p class=\"import-Normal\"><strong>self join<\/strong><strong>:<\/strong> This is when one table is treated as two tables.<\/p>\r\n<p class=\"import-Normal\"><strong>s<\/strong><strong>election \u03c3<\/strong><strong> (The lower case Greek letter sigma<\/strong><strong>):<\/strong> A way of selecting tuples that satisfies a selection condition. This was added to the set operators. Do not confuse this word with the SQL key word \u201cSELECT,\u201d which lists out the desired columns in the output.<\/p>\r\n<p class=\"import-Normal\"><strong>s<\/strong><strong>electivity of the condition<\/strong>: The fraction of tuples selected by a selection condition.<\/p>\r\n<p class=\"import-Normal\"><strong>s<\/strong><strong>emijoin<\/strong>: In a left outer join, you would have the desired columns from both tables. Nulls would appear in the right hand table for missing values. A semijoin would drop the right-hand table\u2019s columns. The result would be the tuples that have a match in the second table.<\/p>\r\n<p class=\"import-Normal\"><strong>set difference<\/strong><strong>:<\/strong> This is from set theory. These are the tuples that are present in one relation, but not present in a second relation. We write this as R \u2013 S, which states that this includes all tuples that are in R, but are not in S. The two relations must be union compatibility or type compatibility.<\/p>\r\n<p class=\"import-Normal\"><strong>set operations<\/strong><strong>: <\/strong>These are operations drawn from mathematical set theory. These are union, intersection, set difference, and Cartesian product.<\/p>\r\n<p class=\"import-Normal\"><strong>t<\/strong><strong>heta <\/strong><strong>join<\/strong> <strong>\u03b8<\/strong> <strong>(The lower case Greek letter <\/strong><strong>theta):<\/strong> This pulls from two tables based on a condition represented by the Greek letter theta (<strong>\u03b8<\/strong>). <strong>\u03b8<\/strong> could be any one of the comparison operators.<\/p>\r\n<p class=\"import-Normal\"><strong>type compatibility<\/strong><strong>:<\/strong> This states that the two database tables must have the same degree and the same domain. This is the same concept as is \u201cunion compatibility.\u201d<\/p>\r\n<p class=\"import-Normal\"><strong>u<\/strong><strong>n<\/strong><strong>ary<\/strong><strong>: <\/strong>This means we are working with one relation or with one database table.<\/p>\r\n<p class=\"import-Normal\"><strong>union<\/strong> <span lang=\"pt-BR\" xml:lang=\"pt-BR\">\u222a<\/span>: This produces the tuples that are in either Result1 or Result2 or both while removing any duplicates. In the relational database world, the two sets of tuples must be of the same type (union compatibility or type compatibility).<\/p>\r\n<p class=\"import-Normal\"><strong>union compatibility<\/strong><strong>:<\/strong> This states that the two database tables must have the same degree and the same domain. This is the same concept as is \u201ctype compatibility.\u201d<\/p>\r\n<p class=\"import-Normal\"><strong>universal quantifier<\/strong> <a class=\"rId28\" title=\"\u2200\" href=\"https:\/\/en.wikipedia.org\/wiki\/%E2%88%80\"><span class=\"import-Hyperlink\">\u2200<\/span><\/a>: This means \u201cfor all.\u201d All tuples must be true for the statement.<\/p>\r\n<p class=\"import-Normal\"><strong>un<\/strong><strong>safe<\/strong>: The expression draws upon members outside of a defined domain.<\/p>\r\n\r\n<h2>Exercises<\/h2>\r\n<p class=\"import-Normal\" style=\"margin-left: 18pt\">1. Explain what is the union operator and the SQL union action. Provide an example of the relational algebra expression and provide an example of the common SQL command. [CS2013 IM\/RD 3, IM\/RD 4; IT2017 ITE-IMA-05a.]<\/p>\r\n<p class=\"import-Normal\" style=\"margin-left: 18pt\">2. Explain what is the intersection operator. Provide an example of the relational algebra expression and provide an example of the common SQL command. [CS2013 IM\/RD 3, IM\/RD 4; IT2017 ITE-IMA-05a.]<\/p>\r\n<p class=\"import-Normal\" style=\"margin-left: 18pt\">3. Explain what is the difference operator. Provide an example of the relational algebra expression. Research your selected DBMS and find out if it supports the set difference operator. [CS2013 IM\/RD 3, IM\/RD 4; IT2017 ITE-IMA-05a.]<\/p>\r\n<p class=\"import-Normal\" style=\"margin-left: 18pt\">4. Explain what is the Cartesian product operator. Provide an informal example of when you might want to use the Cartesian product operator. [CS2013 IM\/RD 3, IM\/RD 4.]<\/p>\r\n<p class=\"import-Normal\" style=\"margin-left: 18pt\">5. Explain what is the select operator and the SELECT key word. Provide an example of the relational algebra expression and provide an example of the common SQL command. [CS2013 IM\/RD 3, IM\/RD 4; IT2017 ITE-IMA-05a.]<\/p>\r\n<p class=\"import-Normal\" style=\"margin-left: 18pt\">6. Explain what is the project operator and the SELECT key word. Provide an example of the relational algebra expression and provide an example of the common SQL command. [CS2013 IM\/RD 3, IM\/RD 4; IT2017 ITE-IMA-05a.]<\/p>\r\n<p class=\"import-Normal\" style=\"margin-left: 18pt\">7. Explain what is the join operator. Experts have different lists of the specialized join operators. List three joins that will provide tuples that satisfies only the conditional. List three joins that will include tuples with missing data. Provide an example of an inner join and provide an example of an outer join. Be sure to include both the formal form and the SQL form. There are 11 parts to this question. [CS2013 IM\/RD 3, IM\/RD 4; IT2017 ITE-IMA-05a.]<\/p>\r\n<p class=\"import-Normal\" style=\"margin-left: 18pt\">8. Explain what is the relational algebra division operator. Provide an informal example. [CS2013 IM\/RD 3, IM\/RD 4.]<\/p>\r\n<p class=\"import-Normal\" style=\"margin-left: 18pt\">9. Explain what is the natural join relational operator. Provide an example of the relational algebra expression and provide an example of the common SQL command. [IT2017 ITE-IMA-05a.]<\/p>\r\n<p class=\"import-Normal\" style=\"margin-left: 18pt\">10. Write queries in the tuple relational calculus for the following:<\/p>\r\n<p class=\"import-Normal\" style=\"margin-left: 18pt;padding-left: 40px\">a. List all hotels<\/p>\r\n<p class=\"import-Normal\" style=\"margin-left: 18pt;text-indent: 18pt\">b. List all single rooms with a price below $200 per night.<\/p>\r\n<p class=\"import-Normal\" style=\"margin-left: 18pt;text-indent: 18pt\">c. List the names and cities of all guests.<\/p>\r\n<p class=\"import-Normal\" style=\"margin-left: 18pt;text-indent: 18pt\">d. List the price and type of all rooms at the Greenbrier Hotel.<\/p>\r\n\r\n<h2>A Running Project<\/h2>\r\n<p class=\"import-Normal\">Continue to work on your project.<\/p>\r\n\r\n<h2>Attribution<\/h2>\r\n<p class=\"import-Normal\">This chapter of <em>Database Design<\/em> is a brand-new addition.<\/p>\r\n<p class=\"import-Normal\"><a id=\"_Hlk165870885\"><\/a>This chapter drew from many sources.<\/p>\r\n\r\n<h2>Image Attributions<\/h2>\r\n<p class=\"import-Normal\">No second edition images were used.<\/p>\r\n\r\n<h2>References<\/h2>\r\n<p class=\"import-Normal\">Fiona Brown. \u201cDBMS Joins: Inner, THETA, Outer, Equi Types of Join Operations,\u201d Guru99, June 28, 2024. <a class=\"rId29\" href=\"https:\/\/www.guru99.com\/joins-sql-left-right.html\"><span class=\"import-Hyperlink\">https:\/\/www.guru99.com\/joins-sql-left-right.html<\/span><\/a><\/p>\r\n<p class=\"import-Normal\">Thomas Connolly and Carolyn Begg<em>. Database Systems<\/em><em>: A<\/em><em> Practical Approach to Design, Implementation, and Management<\/em>, Addison Wesley, 2002, page 88.<\/p>\r\n<p class=\"import-Normal\">\u201cSQL | Division,\u201d Geeks for Geeks, July 3, 2024. <a class=\"rId30\" href=\"https:\/\/www.geeksforgeeks.org\/sql-division\/\"><span class=\"import-Hyperlink\">https:\/\/www.geeksforgeeks.org\/sql-division\/<\/span><\/a><\/p>\r\n\r\n<div id=\"sdfootnote1sym\"><a href=\"#sdfootnote1anc\">1<\/a> These are topics that are covered in greater detail in a discrete mathematics course. The Computing Accreditation Commission of the ABET require that some computing programs cover discrete mathematics. Bachelor computer science programs have at least 15 academic semester hours of mathematics and one of the courses must be discrete mathematics. Bachelor cybersecurity programs must have at least 6 academic semester hours of mathematics and one of the courses must be discrete mathematics. Bachelor information technology programs must have at least 6 academic semester hours of mathematics and one of the courses must be discrete mathematics. For more information see https:\/\/www.abet.org\/accreditation\/accreditation-criteria\/criteria-for-accrediting-computing-programs-2024-2025\/The Engineering Accreditation Commission of the ABET requires the various programs to have mathematics with the \u201cmathematical sophistication at least equivalent to that of introductory calculus.\u201d Discrete mathematics would satisfy this requirement. Cybersecurity Engineering programs must have a course in discrete mathematics. Software engineering programs must have a course in discrete mathematics. For more information, see https:\/\/www.abet.org\/accreditation\/accreditation-criteria\/criteria-for-accrediting-engineering-programs-2024-2025\/<\/div>\r\n<div id=\"sdfootnote2sym\"><a href=\"#sdfootnote2anc\">2<\/a> The Greek letters have been used for a long time.<\/div>\r\n<div id=\"sdfootnote3sym\"><a href=\"#sdfootnote3anc\">3<\/a> In the chapter on SQL commands, we did not address this topic. This will be addressed in another chapter. This is different from using the key word AS for renaming a column in the output.<\/div>\r\n<div id=\"sdfootnote4sym\"><a href=\"#sdfootnote4anc\">4<\/a> Recall that the term degree refers to the number of columns in a table.<\/div>\r\n<div id=\"sdfootnote5sym\"><a href=\"#sdfootnote5anc\">5<\/a> Thomas Connolly and Carolyn Begg wrote this as \u201cEquijon.\u201d Fiona Brown wrote this as \u201cEQUI Join.\u201d<\/div>\r\n<div id=\"sdfootnote6sym\"><a href=\"#sdfootnote6anc\">6<\/a> Fiona Brown used the first two letters from the alphabet and she placed the Greek letter as a subscript.Thomas Connolly and Carolyn Begg used \u201cR\u201d and \u201cS.\u201d They used the letter \u201cF\u201d in the subscript, which stands for the predicate from the Cartesian product of R and S. In their explanation, they wrote \u201cThe predicate F is of the form R.a, <b>\u03b8<\/b>, S.b, where <b>\u03b8<\/b> may be one of the comparison operators (&lt;, \u2264, &gt;, \u2265, =, \u2260).Fiona Brown\u2019s explanation was easier to understand than the very formal Thomas Connolly and Carolyn Beet explanation.<\/div>\r\n<div id=\"sdfootnote7sym\"><a href=\"#sdfootnote7anc\">7<\/a> Again, Fiona Brown used the first two letters from the alphabet. And she wrote the column names a lower case letter and with a space between the word \u201ccolumn\u201d and the number.<\/div>\r\n<div id=\"sdfootnote8sym\"><a href=\"#sdfootnote8anc\">8<\/a> Fiona Brown used the theta expression as the table name. A SQL environment might use a generic name for the column label.<\/div>\r\n<div id=\"sdfootnote9sym\"><a href=\"#sdfootnote9anc\">9<\/a> Fiona Brown used <b>A<\/b><b> <\/b><b>\u27d5<\/b>B.ThomasConnollyandCarolynBeggwrotethisas(RS).Theactualsymbolusedintheirtextbookhadlongerlinesontheleftside\u2014almostlikeacombinationofthesupersetsymbol(\u2283)(U+2283)ontheleftsidewiththejoinsymbol(\u22c8).TheactualleftouterjoinUnicodesymbolsisU+27D5.<b> B. <\/b>masConnollyandCarolynBeggwrotethisas(RS).Theactualsymbolusedintheirtextbookhadlongerlinesontheleftside\u2014almostlikeacombinationofthesupersetsymbol(\u2283)(U+2283)ontheleftsidewiththejoinsymbol(\u22c8).TheactualleftouterjoinUnicodesymbolsisU+27D5.<b> <\/b>asConnollyandCarolynBeggwrotethisas<b>(<\/b><b>R<\/b>S).Theactualsymbolusedintheirtextbookhadlongerlinesontheleftside\u2014almostlikeacombinationofthesupersetsymbol(\u2283)(U+2283)ontheleftsidewiththejoinsymbol(\u22c8).TheactualleftouterjoinUnicodesymbolsisU+27D5.<b> <\/b>).Theactualsymbolusedintheirtextbookhadlongerlinesontheleftside\u2014almostlikeacombinationofthesupersetsymbol(\u2283)(U+2283)ontheleftsidewiththejoinsymbol(\u22c8).TheactualleftouterjoinUnicodesymbolsisU+27D5.<b>\u27d5<\/b>heactualsymbolusedintheirtextbookhadlongerlinesontheleftside\u2014almostlikeacombinationofthesupersetsymbol(\u2283)(U+2283)ontheleftsidewiththejoinsymbol(\u22c8).TheactualleftouterjoinUnicodesymbolsisU+27D5.<b> S<\/b>actualsymbolusedintheirtextbookhadlongerlinesontheleftside\u2014almostlikeacombinationofthesupersetsymbol(\u2283<b>)<\/b>(U+2283)ontheleftsidewiththejoinsymbol(\u22c8).TheactualleftouterjoinUnicodesymbolsisU+27D5.<\/div>\r\n<div id=\"sdfootnote10sym\"><a href=\"#sdfootnote10anc\">10<\/a> Fiona Brown used <b>A<\/b><b> <\/b><b>\u27d6<\/b>B.ThomasConnollyandCarolynBeggwrotethisas(RS).Theactualsymbolusedintheirtextbookhadlongerlinesontherightside\u2014almostlikeacombinationofthesubsetsymbol(\u2282)(U+2282)ontherightsidewiththejoinsymbol(\u22c8).TheactualrightouterjoinUnicodesymbolisU+27D6.<b> B. <\/b>masConnollyandCarolynBeggwrotethisas(RS).Theactualsymbolusedintheirtextbookhadlongerlinesontherightside\u2014almostlikeacombinationofthesubsetsymbol(\u2282)(U+2282)ontherightsidewiththejoinsymbol(\u22c8).TheactualrightouterjoinUnicodesymbolisU+27D6.<b> <\/b>asConnollyandCarolynBeggwrotethisas<b>(<\/b><b>R<\/b>S).Theactualsymbolusedintheirtextbookhadlongerlinesontherightside\u2014almostlikeacombinationofthesubsetsymbol(\u2282)(U+2282)ontherightsidewiththejoinsymbol(\u22c8).TheactualrightouterjoinUnicodesymbolisU+27D6.<b> <\/b>).Theactualsymbolusedintheirtextbookhadlongerlinesontherightside\u2014almostlikeacombinationofthesubsetsymbol(\u2282)(U+2282)ontherightsidewiththejoinsymbol(\u22c8).TheactualrightouterjoinUnicodesymbolisU+27D6.<b>\u27d6<\/b>heactualsymbolusedintheirtextbookhadlongerlinesontherightside\u2014almostlikeacombinationofthesubsetsymbol(\u2282)(U+2282)ontherightsidewiththejoinsymbol(\u22c8).TheactualrightouterjoinUnicodesymbolisU+27D6.<b> <\/b>eactualsymbolusedintheirtextbookhadlongerlinesontherightside\u2014almostlikeacombinationofthesubsetsymbol(\u2282)(U+2282)ontherightsidewiththejoinsymbol(\u22c8).TheactualrightouterjoinUnicodesymbolisU+27D6.<b>S<\/b>actualsymbolusedintheirtextbookhadlongerlinesontherightside\u2014almostlikeacombinationofthesubsetsymbol(\u2282<b>)<\/b>(U+2282)ontherightsidewiththejoinsymbol(\u22c8).TheactualrightouterjoinUnicodesymbolisU+27D6.<\/div>\r\n<div id=\"sdfootnote11sym\"><a href=\"#sdfootnote11anc\">11<\/a> Fiona Brown used <b>A<\/b><b> <\/b><b>\u27d7<\/b>B.ThomasConnollyandCarolynBeggmentionedfullouterjoins,butdidnotillustratethisjoinliketheydidfortheothertwoouterjoins.TheactualfullouterjoinUnicodeisU+27D7.<b> <\/b>.ThomasConnollyandCarolynBeggmentionedfullouterjoins,butdidnotillustratethisjoinliketheydidfortheothertwoouterjoins.TheactualfullouterjoinUnicodeisU+27D7.<b>B. <\/b>masConnollyandCarolynBeggmentionedfullouterjoins,butdidnotillustratethisjoinliketheydidfortheothertwoouterjoins.TheactualfullouterjoinUnicodeisU+27D7.<\/div>\r\n<div id=\"sdfootnote12sym\"><a href=\"#sdfootnote12anc\">12<\/a> Some DBMSs use \u201cLEFT JOIN\u201d and omit the word \u201cOUTER.\u201d<\/div>\r\n<div id=\"sdfootnote13sym\"><a href=\"#sdfootnote13anc\">13<\/a> Some DBMSs use \u201cRIGHT JOIN\u201d and omit the word \u201cOUTER.\u201d<\/div>\r\n<div id=\"sdfootnote14sym\"><a href=\"#sdfootnote14anc\">14<\/a> Fiona Brown did not have an image for the full outer join. This image came from the W 3 schools website.<\/div>\r\n<div id=\"sdfootnote15sym\"><a href=\"#sdfootnote15anc\">15<\/a> Some DBMS use \u201cFULL JOIN\u201d and omit the word \u201cOUTER.\u201d<\/div>\r\n<div id=\"sdfootnote16sym\"><a href=\"#sdfootnote16anc\">16<\/a> The arrangement of the result set follows what Bhanu Priya used in her article. See https:\/\/www.tutorialspoint.com\/explain-division-operation-in-relational-algebra-dbms<\/div>\r\n<div id=\"sdfootnote17sym\"><a href=\"#sdfootnote17anc\">17<\/a> See Andrew Bone. \u201cHow the Division Operator Works in SQL,\u201d LearnSQL, June 4, 2021. https:\/\/learnsql.com\/blog\/sql-division-operator\/<\/div>\r\n<div id=\"sdfootnote18sym\"><a href=\"#sdfootnote18anc\">18<\/a> See https:\/\/mathworld.wolfram.com\/Calculus.html for more information.<\/div>\r\n<div id=\"sdfootnote19sym\"><a href=\"#sdfootnote19anc\">19<\/a> Unicode U+2227<\/div>\r\n<div id=\"sdfootnote20sym\"><a href=\"#sdfootnote20anc\">20<\/a> Unicode U+2203<\/div>\r\n<div id=\"sdfootnote21sym\"><a href=\"#sdfootnote21anc\">21<\/a> Unicode U+2200<\/div>\r\n<div id=\"sdfootnote22sym\"><a href=\"#sdfootnote22anc\">22<\/a> Douglas College has two campuses.<\/div>\r\n<div id=\"sdfootnote23sym\"><a href=\"#sdfootnote23anc\">23<\/a> Augustus De Morgan was a contemporary of Boole. De Morgan came up with two rules of logic that had been known informally.<\/div>\r\n<\/div>","rendered":"<div class=\"chapter-10-relational-algebra,-relational-calculus,-and-relational-theory\">\n<p class=\"import-Normal\">Original Material to the textbook: Fred Strickland<\/p>\n<h2>Learning Outcomes<\/h2>\n<table style=\"width: 467.5pt\">\n<tbody>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"background-color: transparent;border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\"><strong>Computing Sub Discipline<\/strong><\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"background-color: transparent;border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\"><strong>Document Code, Reference Code, and Page Number<\/strong><\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"background-color: transparent;border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\"><strong>Text<\/strong><\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\" style=\"height: 67.9pt\">\n<td class=\"TableGrid-C\" style=\"background-color: transparent;border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Computer Science<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"background-color: transparent;border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">CS2013<\/p>\n<p class=\"import-Normal\">IM\/Relational Databases<\/p>\n<p class=\"import-Normal\">(Pages 115-116)<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"background-color: transparent;border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">3. Demonstrate use of the relational algebra operations from mathematical set theory (union, intersection, difference, and Cartesian product) and the relational algebra operations developed specifically for relational databases (select (restrict), project, join, and division). [Usage]<\/p>\n<p class=\"import-Normal\">4. Write queries in the relational algebra. [Usage]<\/p>\n<p class=\"import-Normal\">5. Write queries in the tuple relational calculus. [Usage]<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\" style=\"height: 67.9pt\">\n<td class=\"TableGrid-C\" style=\"background-color: transparent;border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">\n<\/td>\n<td class=\"TableGrid-C\" style=\"background-color: transparent;border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">CS2023<\/p>\n<p class=\"import-Normal\">DM-Querying: Query Construction<\/p>\n<p class=\"import-Normal\">(Page 118)<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"background-color: transparent;border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">KA Core 2. Relational Algebra<\/p>\n<p class=\"import-Normal\">Non-core 4. Relational Calculus<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\" style=\"height: 82.75pt\">\n<td class=\"TableGrid-C\" style=\"background-color: transparent;border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Information Technology<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"background-color: transparent;border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">IT2017<\/p>\n<p class=\"import-Normal\">ITE-IMA-05 Database organizational architecture [L3]<\/p>\n<p class=\"import-Normal\">(Page 93)<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"background-color: transparent;border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">a. Demonstrate select, project, union, intersection, set difference, and natural join relational operations using simple example relations provided.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>Introduction to Chapter 10<\/h2>\n<p class=\"import-Normal\">We have been looking at relational DBMS from a hands-on or application viewpoint. And we have touched upon the different DBMSs. We have discovered that SQL-92 is not fully implemented by these DBMSs and that there are extensions.<\/p>\n<p class=\"import-Normal\">How do the various DBMS groups discuss things? These groups could use relational algebra and relational calculus as the common language.<\/p>\n<p class=\"import-Normal\">As textbook authors Thomas Connolly and Caroly Begg wrote:<\/p>\n<p class=\"import-Normal\" style=\"margin-left: 36pt\">Both the algebra and the calculus are formal, non-user-friendly languages. They have been used as the basis for other, higher-level Data Manipulation Languages (DML) for relational databases. They are of interest because they illustrate the basic operations required of any DML and because they serve as the standard for comparison for other relational languages.<\/p>\n<p class=\"import-Normal\" style=\"margin-left: 36pt\">The relational calculus is used to measure the selective power of relational languages. A language that can be used to produce any relational that can be derived using the relational calculus is said to be relationally complete. Most relational query languages are relatively complete but have more expressive power than the relational algebra or relational calculus because of additional operations such as calculated, summary, and ordering functions.<\/p>\n<p class=\"import-Normal\">Now you understand the need for this chapter.<\/p>\n<h2>The Third Edition Style Guide<\/h2>\n<p class=\"import-Normal\">This is the style guide that this book will follow for this chapter and for the other chapters.<\/p>\n<table style=\"width: 229.25pt\">\n<tbody>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"background-color: transparent;border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Naming Convention:<\/p>\n<ul>\n<li>All English names<\/li>\n<li>Plural table names<\/li>\n<li>Singular column names<\/li>\n<li>Capitalized words<\/li>\n<li>Pascal Case for composite names<\/li>\n<li>No underscores or special characters<\/li>\n<li>No unique SQL commands<\/li>\n<li>No object prefixes<\/li>\n<\/ul>\n<p class=\"import-Normal\">Using the IE\u2019s Notation with Crow\u2019s Foot Notation.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p class=\"import-Normal\">Figure 10.1 The database style guide. Adapted from https:\/\/vertabelo.com\/blog\/database-schema-naming-conventions\/<\/p>\n<p class=\"import-Normal\">The examples will conform to the style guide.<\/p>\n<h2>Regular Algebra and Relational Algebra<\/h2>\n<p class=\"import-Normal\">Regular Algebra is a mathematical system that has the following:<\/p>\n<ul>\n<li><em>Operands<\/em>: Variables or values<\/li>\n<li><em>Operators<\/em>: Symbols denoting what will be done to the operands.<\/li>\n<\/ul>\n<p class=\"import-Normal\">Relational Algebra is a system that has the following:<\/p>\n<ul>\n<li><em>Operands<\/em> are relations OR variables that represent relations.<\/li>\n<li><em>Operators<\/em> that are designed to do the most common actions that we need to do with relations in a database.<\/li>\n<li>Uses <em>set operations<\/em> from mathematical set theory.\n<ul>\n<li>Union, Intersection, Set Difference, and Cartesian Product<sup class=\"import-FootnoteReference\"><a id=\"sdfootnote1anc\" href=\"#sdfootnote1sym\">1<\/a><\/sup>.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p class=\"import-Normal\">To sum it up, <em>relational algebra<\/em> collects instances of relations as input and gives occurrences of relations as outputs.<\/p>\n<p class=\"import-Normal\">Textbook authors Thomas Connolly and Carolyn Begg wrote:<\/p>\n<p class=\"import-Normal\" style=\"margin-left: 36pt\">The relational algebra is a theoretical language with operations that work on one or more relations to define another relation without changing the original relation(s). Thus, both the operands and the results are relations, and so the output from one operation can become the input to another operation. This allows expressions to be nested in the relational algebra, just as we can nest arithmetic operations. This property is called closure; relations are closed under the algebra, just as numbers are closed under arithmetic operations.<\/p>\n<p class=\"import-Normal\">Figure 10.2 shows the differences between regular algebra and relational algebra.<\/p>\n<table>\n<tbody>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\" style=\"text-align: center\"><strong>Regular Algebra<\/strong><\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\" style=\"text-align: center\"><strong>Relational Algebra<\/strong><\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\" style=\"margin-left: 18pt\">Add +<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\" style=\"margin-left: 36pt\">Union U<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\" style=\"margin-left: 18pt\">Subtract &#8211;<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\" style=\"margin-left: 36pt\">Set difference \u2013<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\" style=\"margin-left: 18pt\">Multiple X or a dot<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\" style=\"margin-left: 36pt\">Cartesian product X<\/p>\n<p class=\"import-Normal\" style=\"margin-left: 54pt\">Also known as \u201cCross Product.\u201d<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\" style=\"margin-left: 18pt\">Divide \/ or \u00f7<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"background-color: transparent;border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\" style=\"margin-left: 36pt\">Division \u00f7<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\" style=\"margin-left: 18pt\">Factoring elements into small elements (Such as X<sup>2<\/sup> + 4X + 4 into (x + 2)(X + 2).)<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"background-color: #d9d9d9;border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">\n<\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p class=\"import-Normal\">Figure 10.2 The differences between regular algebra and relational algebra.<\/p>\n<p class=\"import-Normal\">Set operations have one more operation that does not exist in regular algebra:<\/p>\n<ul>\n<li><em>Intersection<\/em> \u2229<\/li>\n<\/ul>\n<p class=\"import-Normal\">Relational databases go beyond the standard set operations. So the following have been added:<\/p>\n<ul>\n<li><em>Selection<\/em> \u03c3 (The lower case Greek letter sigma)<sup class=\"import-FootnoteReference\"><a id=\"sdfootnote2anc\" href=\"#sdfootnote2sym\">2<\/a><\/sup><\/li>\n<li><em>Projection<\/em> \u03c0 (The lower case Greek letter pi)<\/li>\n<li><em>Renaming<\/em> \u03f8 (The lower case Greek letter rho)<\/li>\n<li><em>Join<\/em> \u22c8<\/li>\n<\/ul>\n<h3>Recall Entity Relationship Model Rules and Relational Scheme Notes<\/h3>\n<p class=\"import-Normal\">Recall from Chapter 5 where we looked at entity relationship data model with integrity rules and constraints. We used some symbols for indicating the functional dependencies.<\/p>\n<ul>\n<li>SIN &#8212;&gt; Name, Address, Birthdate\n<ul>\n<li>The SIN determines Name, address, and Birthdate. For any given SIN, we can determine any other attribute in that record.<\/li>\n<\/ul>\n<\/li>\n<li>SIN, Course &#8212;&gt; DateCompleted\n<ul>\n<li>The SIN and the Course determine the DateCompleted. The SIN and Course could be used to form a composite PK. Or something else might be serving in that role. So we could be working with the candidate key or with an alternative key.<\/li>\n<\/ul>\n<\/li>\n<li>ISBN &#8212;&gt; Title\n<ul>\n<li>This is an example of something that determines only one thing (dependent)<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p class=\"import-Normal\">Recall the relational scheme R(ABCDE). We worked with a table like the following:<\/p>\n<p class=\"import-Normal\"><img decoding=\"async\" src=\"https:\/\/pressbooks.bccampus.ca\/nelson\/wp-content\/uploads\/sites\/2211\/2025\/01\/image1-3.jpeg\" alt=\"image\" width=\"170.105196850394px\" height=\"260.586666666667px\" \/><\/p>\n<p class=\"import-Normal\">Figure 10.3 A relation table.<\/p>\n<h3>Unary Relational Operation: Selection<\/h3>\n<p class=\"import-Normal\">This is one of the operations developed specifically for relational databases. Recall that in SQL we were able to select which columns would appear in the output and we were able to use the WHERE clause to obtain a subset of the rows. In relational algebra, we would express this with the Greek letter \u03c3 and we use this to choose a subset of tuples from a relation that satisfies a selection condition.<\/p>\n<p class=\"import-Normal\">Do not confuse the selection operator with the SQL key word \u201cSELECT.\u201d The former finds the tuples that satisfy a condition whereas the later determines which columns will be selected from the source database tables.<\/p>\n<p class=\"import-Normal\">Figure 10.4 shows two selection queries in both SQL and relational algebra.<\/p>\n<table>\n<tbody>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Select the Employee tuples where the DepartmentID is 4<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Select the Employee tuples where the Salary is greater than $30,000<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">SELECT * FROM Employees<\/p>\n<p class=\"import-Normal\">WHERE DepartmentID = \u20184\u2019<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">SELECT * FROM Employees<\/p>\n<p class=\"import-Normal\">WHERE Salary &gt; 30000<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">\u03c3<sub>DepartmentID<\/sub> <sub>= 4<\/sub> (Employees)<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">\u03c3<sub>Salary<\/sub> <sub>&gt; 30000<\/sub> (Employees)<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p class=\"import-Normal\">Figure 10.4 The differences between SQL command and relational algebra.<\/p>\n<p class=\"import-Normal\">The relational algebra expression has the Greek letter and the table name on the line and the conditional (the WHERE clause) is written as a subscript. Figure 10.5 shows this approach in a large font size.<\/p>\n<table>\n<tbody>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">\u03c3 <sub>&lt;selection condition as a subscript&gt; <\/sub>(Relation or table, normal line)<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p class=\"import-Normal\">Figure 10.5 The syntax in large font..<\/p>\n<p class=\"import-Normal\">We can use the Boolean words of AND and OR. We can use comparison operators (=, &lt;, \u2264, &gt;, \u2265,\u2260). Figure 10.6 shows how this could be done with the two selects from Figure 10.4.<\/p>\n<table>\n<tbody>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Select the Employee tuples where the DepartmentID is 4 OR the Salary is greater than $30,000<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">SELECT * FROM Employees<\/p>\n<p class=\"import-Normal\">WHERE DepartmentID = \u20184\u2019 AND Salary &gt; 30000<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">\u03c3<sub>DepartmentID<\/sub> <sub>= 4<\/sub> <sub>AND <\/sub><sub>Salary <\/sub><sub>&lt; 30000<\/sub> (Employees)<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p class=\"import-Normal\">Figure 10.6 An example of a compound SQL command with a WHERE clause and a compound clause in Relational Algebra<\/p>\n<p class=\"import-Normal\">Relational algebra uses a shorthand:<\/p>\n<ul>\n<li>The individual tuple is written as \u201ct.\u201d<\/li>\n<li>The relation is written as \u201cR.\u201d<\/li>\n<li>The attribute is written as \u201cAi.\u201d<\/li>\n<li>We can write this as t[Ai].<\/li>\n<\/ul>\n<p class=\"import-Normal\">We use the term \u201c<em>unary<\/em>,\u201d because we are dealing with a single relation or table and we are looking at each tuple individually.<\/p>\n<p class=\"import-Normal\">Look at this expression: |\u03c3<sub>c<\/sub> (R)| \u2264 |R|<\/p>\n<p class=\"import-Normal\">This is stating that the results of a selection will either be the whole table or a subset of the table. We can NEVER have a result set with more rows than what appeared in the original table. Again, we can NEVER have more columns than the original table.<\/p>\n<p class=\"import-Normal\">Terms may be used to describe the behavior of the selection.<\/p>\n<ul>\n<li><em>Selectivity of the condition<\/em>.\n<ul>\n<li>The fraction of tuples selected by a selection condition.<\/li>\n<\/ul>\n<\/li>\n<li><em>Commutative<\/em>\n<ul>\n<li>The sequence of the selects can be applied in any order.<\/li>\n<li>\u03c3<sub>&lt;Condition1&gt; <\/sub>(\u03c3<sub>&lt;Condition2&gt;) <\/sub>(R)) = \u03c3<sub>&lt;Condition2&gt; <\/sub>(\u03c3<sub>&lt;Condition1&gt;) <\/sub>(R))<\/li>\n<\/ul>\n<\/li>\n<li>Cascade or sequence\n<ul>\n<li>You could nest a query as done in commutative. Or you could express this as a conjunction (the key word AND).<\/li>\n<li>\u03c3<sub>&lt;Condition1&gt; <\/sub>(\u03c3<sub>&lt;Condition2&gt;) <\/sub>(R)) = \u03c3<sub>&lt;Condition2&gt; <\/sub>AND<sub>&lt;Condition1&gt;) <\/sub>(R))<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p class=\"import-Normal\">We can use an example to understand the foregoing better. Vancouver British Columbia is home to Douglas College and to other institutions. We wish to find those individuals who have a connection to Douglas College as active students.<\/p>\n<ul>\n<li>Commutative: You could select all persons with a connection to Douglas College, then select out a list of active students. Or you could select out all active students from all institutions, then select out those with a connection to Douglas College. The resulting set would be the same.<\/li>\n<li>Cascade or sequence: Use either commutative approach or you could select all persons with a connection to Douglas College and a status as active student. And the order does not matter.<\/li>\n<\/ul>\n<h3>Unary Relational Operation: Projection<\/h3>\n<p class=\"import-Normal\">Projection is one of the operations developed specifically for relational databases. Selection will return all of the columns in a table. <em>Projection<\/em> permits us to select some of the columns from a table. The SQL key word \u201cSELECT\u201d does the same thing.<\/p>\n<table>\n<tbody>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">We want just an employee\u2019s last name, first name, and salary.<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">SELECT LastName, FirstName, Salary FROM Employees<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">\u03c0 <sub>LastName, FirstName, <\/sub><sub>Salary<\/sub>(Employees)<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p class=\"import-Normal\">Figure 10.7 An example of projection in Relational Algebra<\/p>\n<p class=\"import-Normal\">Notice that the column names are written as subscripts.<\/p>\n<p class=\"import-Normal\">The projection operator has some interesting behaviors. If non-key attributes are used, then duplicate tuples are possible. If a key is used, then duplicate tuples cannot happen.<\/p>\n<p class=\"import-Normal\">In the formal relational model, duplicates are not permitted. In SQL, this is allowed. To have this behavior, we would use the key word DISTINCT. In some circles, this is called a multiset or a bag of tuples.<\/p>\n<p class=\"import-Normal\">Since projection is a special form of selection, the selection traits are present too. The exception is the property of commutativity. We cannot change the ordering of the columns in the column name list and have the same results in the output.<\/p>\n<h3>Unary Relational Operation: Renaming<\/h3>\n<p class=\"import-Normal\"><em>Renaming<\/em> is one of the operations developed specifically for relational databases. We use this operator in order to rename the output columns. Recall from regular algebra how you could use an immediate variable.<\/p>\n<table>\n<tbody>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\" style=\"text-align: center\"><strong>Example of an Algebra Problem Using Immediate Variables.<\/strong><\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">X + Y + Z<\/p>\n<p class=\"import-Normal\">Let A = X + Y<\/p>\n<p class=\"import-Normal\">Answer: A + Z<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p class=\"import-Normal\">Figure 10.8 An example of an algebra problem using an immediate variable<\/p>\n<p class=\"import-Normal\">This is similar to software programming where a variable is declared to hold a temporary value. The following snippet of Java code shows how we can change the stored values.<\/p>\n<ul>\n<li>int A = 2;<\/li>\n<li>int B = 3;<\/li>\n<li>int C = 4;<\/li>\n<li>int temp;<\/li>\n<li>temp = A; \/\/ The variable temp is holding the value of 2.<\/li>\n<li>A = B; \/\/ The variable A has taken on the new value of 3.<\/li>\n<li>B = C; \/\/ The variable B has taken on the new value of 4.<\/li>\n<li>C = temp; \/\/ The variable C has taken on the new value of 2.<\/li>\n<li>System.out.println (\u201cA is \u201c + A + \u201c. B is \u201c + B + \u201c. C is \u201c + C + \u201c.\u201d);<\/li>\n<li>The output string is: A is 3. B is 4. C is 2.<\/li>\n<\/ul>\n<p class=\"import-Normal\">The variable temp preserves the value that was originally stored in the variable A. Otherwise, this value would be lost as soon as the value stored in B is sent to the variable A.<\/p>\n<p class=\"import-Normal\">Consider the example of retrieving the first name, last name, and salary of all employees who work in department number 5.<\/p>\n<p class=\"import-Normal\">We select all employees that work in department number 5. We limit the columns just to the first name, the last name, and the salary (via the projection operator). This could have been done in two steps. The output from the department number 5 employees would be stored in a temporary variable<sup class=\"import-FootnoteReference\"><a id=\"sdfootnote3anc\" href=\"#sdfootnote3sym\">3<\/a><\/sup>. Then we would take that temporary variable and feed it to the column selecting SQL.<\/p>\n<table>\n<tbody>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\" style=\"text-align: center\"><strong>Using Renaming Command<\/strong><\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">DEP5_EMPS &lt;&#8212; \u03c3<sub>DepartmentID<\/sub><sub> = 5 <\/sub>(Employees)<\/p>\n<p class=\"import-Normal\">RESULTS &lt;&#8212; \u03c0 <sub>FirstName, LastName, Salary <\/sub>(DEP5_EMPS )<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p class=\"import-Normal\">Figure 10.9 An example of relational algebra using an immediate variable (DEPT_EMPS)<\/p>\n<p class=\"import-Normal\">Notice that in relational algebra that we do not use the Greek letter rho (\u03f8). Instead, we use the left pointing arrow with a long tail.<\/p>\n<p class=\"import-Normal\">We use the Greek letter rho (\u03f8) when we are discussing the options as for listing out the three forms of renaming:<\/p>\n<p class=\"import-Normal\" style=\"margin-left: 36pt\">\u03f8 <sub>S(<\/sub><sub>B1, B2, &#8230;, Bn<\/sub>)(R) or \u03f8 <sub>S<\/sub>(R) or \u03f8<sub lang=\"el-GR\" xml:lang=\"el-GR\">(<\/sub><sub>B1, B2, &#8230;, Bn)<\/sub>(R)<\/p>\n<ul>\n<li>Where \u03f8 is the RENAME operator.<\/li>\n<li>Where S is the new relation name.<\/li>\n<li>Where B1, B2, .., Bn are the new attribute names.<\/li>\n<\/ul>\n<p class=\"import-Normal\">A bit more explanation:<\/p>\n<ul>\n<li>\u03f8 <sub>S(<\/sub><sub>B1, B2, &#8230;, Bn<\/sub>)(R) is renaming both the relation and its attributes<\/li>\n<li>\u03f8 <sub>S<\/sub>(R) is renaming only the relation<\/li>\n<li>\u03f8<sub lang=\"el-GR\" xml:lang=\"el-GR\">(<\/sub><sub>B1, B2, &#8230;, Bn)<\/sub>(R) is renaming the attributes.<\/li>\n<\/ul>\n<p class=\"import-Normal\">How the attributes are ordered in the original relation is how the new attributes are ordered in the new relation.<\/p>\n<h3>Binary Relational Operation: Union and Intersection<\/h3>\n<p class=\"import-Normal\">Union and intersection are operations from set theory.<\/p>\n<p class=\"import-Normal\">We have worked with the SQL union command. An example will show how this operator is used.<\/p>\n<p class=\"import-Normal\">We wish to retrieve the Social Security numbers of all employees who either work in department 5 or directly supervise an employee who works in department 5.<\/p>\n<p class=\"import-Normal\">We could do this with temporary results via renaming and a union operation.<\/p>\n<p class=\"import-Normal\" style=\"margin-left: 36pt\">Result1 \u2190 \u03c0 Ssn(DEP5_EMPS)<\/p>\n<p class=\"import-Normal\" style=\"margin-left: 36pt\">Result2 \u2190 \u03c0 Super_ssn(DEP5_EMPS)<\/p>\n<p class=\"import-Normal\" style=\"margin-left: 36pt\">Result \u2190 Result1 U Result2<\/p>\n<p class=\"import-Normal\">The <em>u<\/em><em>nion<\/em> operation produces the tuples that are in either Result1 or Result2 or both while removing any duplicates.<\/p>\n<p class=\"import-Normal\">The intersection operation produces the tuples that are in both.<\/p>\n<p class=\"import-Normal\">In the relational database world, the two sets of tuples must be of the same type (union compatibility or type compatibility).<\/p>\n<p class=\"import-Normal\">We formally express <em>union compatibility<\/em> or <em>type compatibility<\/em> thusly:<\/p>\n<ul>\n<li>Two relations R(A1, A2, &#8230;, An) and S(B1, B2, &#8230;, Bn) are said to be union compatible (or type compatible) if they have the same degree<sup class=\"import-FootnoteReference\"><a id=\"sdfootnote4anc\" href=\"#sdfootnote4sym\">4<\/a><\/sup> n and if dom(Ai) = dom(Bi) for 1 \u2264 I \u2264 n.<\/li>\n<li>This means that the two relations have the same number of attributes (columns) and each corresponding pair of attributes has the same domain.<\/li>\n<\/ul>\n<p class=\"import-Normal\">Union and intersection are commutative operations.<\/p>\n<ul>\n<li><span lang=\"pt-BR\" xml:lang=\"pt-BR\">R <\/span><span lang=\"pt-BR\" xml:lang=\"pt-BR\">\u222a<\/span><span lang=\"pt-BR\" xml:lang=\"pt-BR\"> S = S <\/span><span lang=\"pt-BR\" xml:lang=\"pt-BR\">\u222a<\/span><span lang=\"pt-BR\" xml:lang=\"pt-BR\"> R <\/span><\/li>\n<li><span lang=\"pt-BR\" xml:lang=\"pt-BR\">R \u2229 S = S \u2229 R <\/span><\/li>\n<\/ul>\n<p class=\"import-Normal\">Union and intersection are associative operations. The grouping of the operations does not matter:<\/p>\n<ul>\n<li>R \u222a (S \u222a T) = (R \u222a S) \u222a T<\/li>\n<li>R \u2229 (S \u2229 T) = (R \u2229 S) \u2229 T<\/li>\n<\/ul>\n<h3>Binary Relational Operation: Set Difference<\/h3>\n<p class=\"import-Normal\"><em>Set difference<\/em> operation is from set theory.<\/p>\n<p class=\"import-Normal\">These are the tuples that are present in one relation, but not present in a second relation. We write this as R \u2013 S, which states that this includes all tuples that are in R, but are not in S.<\/p>\n<p class=\"import-Normal\">The two relations must be union compatibility or type compatibility.<\/p>\n<p class=\"import-Normal\">Commutative operations cannot be applied to a set difference action.<\/p>\n<p class=\"import-Normal\">In mathematics, an operation could be rewritten in different ways. Consider the following:<\/p>\n<ul>\n<li>9 times 10<\/li>\n<li>9 + 9 + 9 + 9 + 9 + 9 + 9 + 9 + 9 + 9<\/li>\n<li>10 + 10 + 10 + 10 +10 + 10 + 10 + 10 + 10<\/li>\n<li>10 times 10 \u2013 10<\/li>\n<\/ul>\n<p class=\"import-Normal\">Prove to yourself that the answer for each line is 90.<\/p>\n<p class=\"import-Normal\">In binary relations, you could do the same thing. You could rewrite an intersection action as a series of unions and set differences:<\/p>\n<ul>\n<li><span lang=\"pt-BR\" xml:lang=\"pt-BR\">R \u2229 S = ((R <\/span><span lang=\"pt-BR\" xml:lang=\"pt-BR\">\u222a<\/span> <span lang=\"pt-BR\" xml:lang=\"pt-BR\">S )<\/span><span lang=\"pt-BR\" xml:lang=\"pt-BR\"> \u2212 (R \u2212S )) \u2212 (S \u2212R)<\/span><\/li>\n<\/ul>\n<h3>Binary Relational Operation: Cartesian Product<\/h3>\n<p class=\"import-Normal\"><em>Cartesian <\/em><em>product<\/em> is an operation from set theory. This is also known as \u201ccross product.\u201d If we drop the requirement that a relation must be union compatible, then you could have an output that is larger than either relation. The result is a new element by combining every member tuple from one relation set with every member tuple from the other relation set. In formal expression, we would write this as:<\/p>\n<ul>\n<li>R(A1, A2, &#8230;, An) X S(B1, B2, &#8230;, Bm) is a relation Q with degree n + m attributes Q(A1, A2, &#8230;, An, B1, B2, &#8230;, Bm), in that order.<\/li>\n<\/ul>\n<p class=\"import-Normal\">If you create a join command and leave off the WHERE clause, then the result would be a Cartesian product. Suppose we wanted to output a list of every female employee with their children. We would need to include a WHERE clause of the female employee\u2019s company ID number from two tables (the Employees table and the Dependents table). If the WHERE clause is omitted, then the output would have EVERY dependent name combined with EVERY female employee. Clearly this is not very useful.<\/p>\n<p class=\"import-Normal\">Is there a place for the Cartesian product? Yes. Suppose you are in your favorite breakfast caf\u00e9. The menu has two columns as shown in Figure 10.10:<\/p>\n<table>\n<tbody>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\" style=\"text-align: center\"><strong>Proteins<\/strong><\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\" style=\"text-align: center\"><strong>Sides<\/strong><\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Chicken<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Mushroom Pasta<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Salmon<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Spinach and Mushrooms<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Cod<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Slaw<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Scallops<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Sun-dried tomatoes<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Octopus<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Arugula salad<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"background-color: #d9d9d9;border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Broccoli<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p class=\"import-Normal\">Figure 10.10 An example of a menu with five proteins and six sides<\/p>\n<p class=\"import-Normal\">You do not wish to eat the same combination twice in a 30-day period. Using mathematics, you know that 5 times 6 is 30. And you could work this out by hand:<\/p>\n<table>\n<tbody>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Chicken<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Salmon<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Cod<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Scallops<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Octopus<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Mushroom Pasta<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Mushroom Pasta<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Mushroom Pasta<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Mushroom Pasta<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Mushroom Pasta<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Spinach and Mushrooms<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Spinach and Mushrooms<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Spinach and Mushrooms<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Spinach and Mushrooms<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Spinach and Mushrooms<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Slaw<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Slaw<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Slaw<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Slaw<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Slaw<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Sun-dried tomatoes<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Sun-dried tomatoes<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Sun-dried tomatoes<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Sun-dried tomatoes<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Sun-dried tomatoes<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Arugula salad<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Arugula salad<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Arugula salad<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Arugula salad<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Arugula salad<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Broccoli<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Broccoli<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Broccoli<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Broccoli<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Broccoli<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p class=\"import-Normal\">Figure 10.11 Working out by hand the 30 possible combinations<\/p>\n<p class=\"import-Normal\">Using Cartesian product or leaving off the WHERE clause, the output would be as follows:<\/p>\n<table>\n<tbody>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Chicken<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Mushroom Pasta<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Chicken<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Spinach and Mushrooms<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Chicken<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Slaw<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Chicken<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Sun-dried tomatoes<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Chicken<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Arugula salad<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Chicken<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Broccoli<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Salmon<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Mushroom Pasta<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Salmon<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Spinach and Mushrooms<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Salmon<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Slaw<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Salmon<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Sun-dried tomatoes<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Salmon<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Arugula salad<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Salmon<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Broccoli<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Cod<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Mushroom Pasta<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Cod<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Spinach and Mushrooms<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Cod<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Slaw<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Cod<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Sun-dried tomatoes<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Cod<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Arugula salad<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Cod<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Broccoli<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Scallops<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Mushroom Pasta<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Scallops<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Spinach and Mushrooms<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Scallops<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Slaw<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Scallops<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Sun-dried tomatoes<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Scallops<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Arugula salad<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Scallops<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Broccoli<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Octopus<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Mushroom Pasta<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Octopus<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Spinach and Mushrooms<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Octopus<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Slaw<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Octopus<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Sun-dried tomatoes<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Octopus<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Arugula salad<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Octopus<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Broccoli<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p class=\"import-Normal\">Figure 10.12 Using Cartesian product to obtain the 30 possible combinations<\/p>\n<h3>Binary Relational Operation: Join Operation<\/h3>\n<p class=\"import-Normal\"><em>Join<\/em><em> operation<\/em> is an operation from set theory. A relational database is powerful, because of the ability to pull data from two or more tables. The output could have more fields or columns than one of the input tables. This is similar to the traits of a Cartesian product. The difference is that we use a WHERE clause to select out the useful rows.<\/p>\n<p class=\"import-Normal\">As Thomas Connolly and Carolyn Begg pointed out:<\/p>\n<ul>\n<li>Join is one of the most difficult operations to implement efficiently in a\u2026 [relational] DBMS and is one of the reasons why relational systems have intrinsic performance problems.<\/li>\n<\/ul>\n<p class=\"import-Normal\">Imagine that we wish to retrieve the name of each manager for each department in an organization. The Departments table contains the SSN for the manager. The Employees table contains the names of the managers. Recall that we used normalization and that is why the managers\u2019 names and other details are not stored in the Departments table. The manager\u2019s SSN is a foreign key in the Departments table. Here is the join command as expressed in relational algebra:<\/p>\n<ul>\n<li>DepartmentManager \u2190Departments \u22c8 <sub>ManagerSSN<\/sub><sub>=SSN<\/sub> Employees<\/li>\n<\/ul>\n<p class=\"import-Normal\">This would create a long tuple. We can remove the unwanted columns by using projection:<\/p>\n<ul>\n<li>Result \u2190\u03c0<sub>DepartmentName<\/sub><sub>, LastName, <\/sub><sub>FirstName<\/sub>(DepartmentManager)<\/li>\n<\/ul>\n<p class=\"import-Normal\">If the Departments table used \u201cSSN\u201d instead of \u201cManagerSSN,\u201d then the line would appear as<\/p>\n<ul>\n<li>DepartmentManager \u2190Departments \u22c8 <sub>Departments.SSN<\/sub><sub>=<\/sub><sub>Employees.SSN<\/sub>Employees<\/li>\n<\/ul>\n<p class=\"import-Normal\">Notice the table name, the period (the \u201cdot\u201d), and the field or column name.<\/p>\n<p class=\"import-Normal\">According to Thomas Connoly and Carolyn Begg, there are five types of join operations<\/p>\n<ul>\n<li>Theta join<\/li>\n<li>Equijoin<\/li>\n<li>Natural join<\/li>\n<li>Outer join<\/li>\n<li>Semijoin<\/li>\n<\/ul>\n<p class=\"import-Normal\">An inner join will return rows from two tables that satisfies a given condition. This is the most widely used join operation. An inner join can be divided into three sub types:<\/p>\n<ul>\n<li>Theta join<\/li>\n<li>Equijoin<sup class=\"import-FootnoteReference\"><a id=\"sdfootnote5anc\" href=\"#sdfootnote5sym\">5<\/a><\/sup><\/li>\n<li>Natural join<\/li>\n<\/ul>\n<h4>Theta Join<\/h4>\n<p class=\"import-Normal\">A <em>theta <\/em><em>join<\/em> pulls from two tables based on a condition represented by the Greek letter theta (<strong>\u03b8<\/strong>). <strong>\u03b8<\/strong> could be any one of the comparison operators. The general form is:<\/p>\n<table>\n<tbody>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\" style=\"text-align: center\"><strong>Formal Form<\/strong><\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\" style=\"text-align: center\"><strong>SQL Form<\/strong><\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\" style=\"margin-left: 9pt\">R \u22c8<sub>\u03b8<\/sub> S<sup class=\"import-FootnoteReference\"><a id=\"sdfootnote6anc\" href=\"#sdfootnote6sym\">6<\/a><\/sup><\/p>\n<p class=\"import-Normal\">\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">SELECT &lt;column names&gt;<\/p>\n<p class=\"import-Normal\">FROM &lt;first table name&gt;<\/p>\n<p class=\"import-Normal\">INNER JOIN &lt;second table name&gt; ON &lt;first table name column&gt; = &lt;second table name column&gt;<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p class=\"import-Normal\">Figure 10.13 The formal form and the SQL form of a theta (<strong>\u03b8<\/strong><strong>)<\/strong> join.<\/p>\n<p class=\"import-Normal\">To understand theta joins better, consider the following example:<\/p>\n<table>\n<tbody>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\" colspan=\"2\">\n<p class=\"import-Normal\" style=\"text-align: center\">TableA<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"background-color: #d9d9d9;border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\" colspan=\"2\">\n<p class=\"import-Normal\" style=\"text-align: center\">TableB<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Column1<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Column2<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"background-color: #d9d9d9;border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Column1<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Column2<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">1<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">1<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"background-color: #d9d9d9;border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">1<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">1<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">1<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">2<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"background-color: #d9d9d9;border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">1<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">3<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p class=\"import-Normal\">Figure 10.14 The theta (<strong>\u03b8<\/strong><strong>) <\/strong>join example with two tables. Adapted from Fiona Brown\u2019s example. (Corrected to conform with the Third Edition Style Guide.) Source: https:\/\/www.guru99.com\/joins-sql-left-right.html<\/p>\n<p class=\"import-Normal\">We will take R \u22c8<sub>\u03b8<\/sub> S and rewrite it as:<\/p>\n<p class=\"import-Normal\" style=\"margin-left: 36pt\">R \u22c8 <sub>R.Column<\/sub><sub>2 &gt; S.Column2<\/sub> (S)<sup class=\"import-FootnoteReference\"><a id=\"sdfootnote7anc\" href=\"#sdfootnote7sym\">7<\/a><\/sup><\/p>\n<p class=\"import-Normal\">The output would be<sup class=\"import-FootnoteReference\"><a id=\"sdfootnote8anc\" href=\"#sdfootnote8sym\">8<\/a><\/sup><\/p>\n<table>\n<tbody>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\" colspan=\"2\">\n<p class=\"import-Normal\">R \u22c8 R.Column2 &gt; S.Column2 (S)<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Column1<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Column2<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">1<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">2<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p class=\"import-Normal\">Figure 10.15 The theta (<strong>\u03b8<\/strong><strong>) <\/strong>join example output table. Adapted from Fiona Brown\u2019s example. (Corrected to conform with the Third Edition Style Guide.) Source: https:\/\/www.guru99.com\/joins-sql-left-right.html<\/p>\n<p class=\"import-Normal\">This example is very simple and is a bit misleading. In a theta join (and in the equijoin), both columns that are mentioned in the conditional clause would appear in the output.<\/p>\n<h4>Equijoin<\/h4>\n<p class=\"import-Normal\">An <em>equijoin<\/em> is like a theta join in that the equijoin operation pulls from two tables based on a condition represented by the Greek letter theta (<strong>\u03b8<\/strong>). But <strong>\u03b8<\/strong> is the equal symbol (=). We will use the previous example to illustrate the equijoin.<\/p>\n<p class=\"import-Normal\" style=\"margin-left: 36pt\">R \u22c8 <sub>R.Column<\/sub><sub>2 = S.Column2<\/sub> (S)<\/p>\n<p class=\"import-Normal\">The output would be<\/p>\n<table>\n<tbody>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\" colspan=\"2\">\n<p class=\"import-Normal\">R\u22c8R.Column2 = S.Column2 (S)<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Column1<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Column2<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">1<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">1<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p class=\"import-Normal\">Figure 10.16 The equijoin example output table. Adapted from Fiona Brown\u2019s example. (Corrected to conform with the Third Edition Style Guide.) Source: https:\/\/www.guru99.com\/joins-sql-left-right.html<\/p>\n<p class=\"import-Normal\">Equijoin is not a SQL key word. The WHERE clause contains the equal symbol.<\/p>\n<h4>Natural Join<\/h4>\n<p class=\"import-Normal\">A <em>natural <\/em><em>join<\/em> is like a theta join that pulls from two tables, but the extra column is not included in the output and the ON key word is not used. So in Figure 10.13, there would be no theta expression and there would be no ON clause.<\/p>\n<p class=\"import-Normal\">Recall that in the union operation, the number of attributes must be the same and the domain types need to be the same. For the natural join, there is the additional requirement that the two tables share at least one common attribute. A natural join will match the common column values and eliminate any duplications. We will use a different example to illustrate a natural join.<\/p>\n<table>\n<tbody>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\" colspan=\"2\">\n<p class=\"import-Normal\" style=\"text-align: center\">Squares<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"background-color: #d9d9d9;border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\" colspan=\"2\">\n<p class=\"import-Normal\" style=\"text-align: center\">Cubes<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Number<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Square<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"background-color: #d9d9d9;border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Number<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Cube<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">2<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">4<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"background-color: #d9d9d9;border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">2<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">8<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">3<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">9<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"background-color: #d9d9d9;border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">3<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">18<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p class=\"import-Normal\">Figure 10.17 The natural join example tables. Adapted from Fiona Brown\u2019s example. (Corrected to conform with the Third Edition Style Guide.) Source: https:\/\/www.guru99.com\/joins-sql-left-right.html<\/p>\n<p class=\"import-Normal\">We would write the natural join as<\/p>\n<table>\n<tbody>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\" style=\"text-align: center\"><strong>Formal Expression<\/strong><\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\" style=\"text-align: center\"><strong>SQL Expression<\/strong><\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\" style=\"margin-left: 13.5pt\">Squares \u22c8 Cubes<\/p>\n<p class=\"import-Normal\">\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">SELECT *<\/p>\n<p class=\"import-Normal\">FROM Squares<\/p>\n<p class=\"import-Normal\">NATUAL JOIN Cubes;<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p class=\"import-Normal\">Figure 10.18 The formal form and the SQL form of the natural join for Figure 10.17.<\/p>\n<p class=\"import-Normal\">The output would be<\/p>\n<table>\n<tbody>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\" colspan=\"3\">\n<p class=\"import-Normal\">Squares \u22c8 Cubes<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Number<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Square<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Cube<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">2<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">4<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">8<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">3<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">9<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">18<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p class=\"import-Normal\">Figure 10.19 The example output table for the natural join. Adapted from Fiona Brown\u2019s example. (Corrected to conform with the Third Edition Style Guide.) Source: https:\/\/www.guru99.com\/joins-sql-left-right.html<\/p>\n<h4>Outer Joins<\/h4>\n<p class=\"import-Normal\">An <em>outer <\/em><em>join<\/em> will return rows from two tables even if there are no matches in one of the tables. An outer join can be divided into three sub types:<\/p>\n<ul>\n<li>Left outer join <strong>(<\/strong><strong>R<\/strong> <strong>\u27d5<\/strong><strong> S<\/strong><strong>)<\/strong><sup class=\"import-FootnoteReference\"><strong><a id=\"sdfootnote9anc\" href=\"#sdfootnote9sym\">9<\/a><\/strong><\/sup><\/li>\n<li>Right outer join <strong>(<\/strong><strong>R<\/strong> <strong>\u27d6<\/strong> <strong>S<\/strong><strong>)<\/strong><sup class=\"import-FootnoteReference\"><strong><a id=\"sdfootnote10anc\" href=\"#sdfootnote10sym\">10<\/a><\/strong><\/sup><\/li>\n<li>Full outer join <strong>(<\/strong><strong>R<\/strong> <strong>\u27d7<\/strong> <strong>S<\/strong><strong>)<\/strong><sup class=\"import-FootnoteReference\"><strong><a id=\"sdfootnote11anc\" href=\"#sdfootnote11sym\">11<\/a><\/strong><\/sup><\/li>\n<\/ul>\n<p class=\"import-Normal\">The outer join is a join in which the tuples from one relation are included even though there is no match in the second relation.<\/p>\n<h4>Left Outer Join<\/h4>\n<p class=\"import-Normal\">For the left outer join, you could imagine that the main table is on the \u201cleft\u201d and the second table is on the \u201cright.\u201d Figure 10.20 uses Venn diagrams to illustrate this operation:<\/p>\n<p class=\"import-Normal\"><img decoding=\"async\" src=\"https:\/\/pressbooks.bccampus.ca\/nelson\/wp-content\/uploads\/sites\/2211\/2025\/01\/image2-4.png\" alt=\"image\" width=\"539.866666666667px\" height=\"143.466666666667px\" \/><\/p>\n<p class=\"import-Normal\">Figure 10.20 Venn diagrams illustrating a left outer join. Source of image: https:\/\/www.guru99.com\/joins-sql-left-right.html<\/p>\n<p class=\"import-Normal\">To see this from a different viewpoint, we will take the table from Figure 10.17 and add another row.<\/p>\n<table>\n<tbody>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\" colspan=\"2\">\n<p class=\"import-Normal\" style=\"text-align: center\">Squares<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"background-color: #d9d9d9;border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\" colspan=\"2\">\n<p class=\"import-Normal\" style=\"text-align: center\">Cubes<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Number<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Square<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"background-color: #d9d9d9;border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Number<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Cube<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">2<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">4<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"background-color: #d9d9d9;border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">2<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">8<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">3<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">9<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"background-color: #d9d9d9;border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">3<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">18<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">4<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">16<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"background-color: #d9d9d9;border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">5<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">75<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p class=\"import-Normal\">Figure 10.21 The source tables for the outer joins. Adapted from Fiona Brown\u2019s example. (Corrected to conform with the Third Edition Style Guide.) Source: https:\/\/www.guru99.com\/joins-sql-left-right.html<\/p>\n<p class=\"import-Normal\">We would write the left outer join as<\/p>\n<table>\n<tbody>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\" style=\"text-align: center\"><strong>Formal Expression<\/strong><\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\" style=\"text-align: center\"><strong>SQL Expression<\/strong><\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\" style=\"margin-left: 13.5pt\">Squares <strong>\u27d5<\/strong> Cubes<\/p>\n<p class=\"import-Normal\">\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">SELECT &lt;column names&gt;<\/p>\n<p class=\"import-Normal\">FROM Squares<\/p>\n<p class=\"import-Normal\">LEFT OUTER<sup class=\"import-FootnoteReference\"><a id=\"sdfootnote12anc\" href=\"#sdfootnote12sym\">12<\/a><\/sup> JOIN Cubes ON Squares.Number = Cubes.Number<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p class=\"import-Normal\">Figure 10.22 The formal form and the SQL form of the left outer join for Figure 10.21.<\/p>\n<p class=\"import-Normal\">The output would be<\/p>\n<table>\n<tbody>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\" colspan=\"3\">\n<p class=\"import-Normal\">Squares <strong>\u27d5<\/strong> Cubes<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Number<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Square<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Cube<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">2<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">4<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">8<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">3<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">9<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">18<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">4<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">16<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">NULL<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p class=\"import-Normal\">Figure 10.23 The example output table for the left outer join. Adapted from Fiona Brown\u2019s example. (Corrected to conform with the Third Edition Style Guide.) Source: https:\/\/www.guru99.com\/joins-sql-left-right.html<\/p>\n<p class=\"import-Normal\">Again, all of the Squares table rows are included in the output plus any matching rows from the Cubes table rows. Any \u201cmissing\u201d rows in this table are noted as NULLs.<\/p>\n<p class=\"import-Normal\">If you only want the columns from the left table, then you would use the <em>semijoin<\/em>.<\/p>\n<h4>Right Outer Join<\/h4>\n<p class=\"import-Normal\">For the right outer join, you could imagine that the main table is on the \u201cright\u201d and the second table is on the \u201cleft.\u201d Figure 10.24 uses Venn diagrams to illustrate this operation:<\/p>\n<p class=\"import-Normal\"><img decoding=\"async\" src=\"https:\/\/pressbooks.bccampus.ca\/nelson\/wp-content\/uploads\/sites\/2211\/2025\/01\/image3-4.png\" alt=\"image\" width=\"542.133333333333px\" height=\"138.933333333333px\" \/><\/p>\n<p class=\"import-Normal\">Figure 10.24 Venn diagrams illustrating a right outer join. Source of image: https:\/\/www.guru99.com\/joins-sql-left-right.html<\/p>\n<p class=\"import-Normal\">To see this from a different viewpoint, we will take the table from Figure 10.17.<\/p>\n<p class=\"import-Normal\">We would write the right outer join as<\/p>\n<table>\n<tbody>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\" style=\"text-align: center\"><strong>Formal Expression<\/strong><\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\" style=\"text-align: center\"><strong>SQL Expression<\/strong><\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\" style=\"margin-left: 13.5pt\">Squares <strong>\u27d6<\/strong> Cubes<\/p>\n<p class=\"import-Normal\">\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">SELECT &lt;column names&gt;<\/p>\n<p class=\"import-Normal\">FROM Cubes<\/p>\n<p class=\"import-Normal\">RIGHT OUTER<sup class=\"import-FootnoteReference\"><a id=\"sdfootnote13anc\" href=\"#sdfootnote13sym\">13<\/a><\/sup> JOIN Squares ON Cubes.Number = Squares.Number<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p class=\"import-Normal\">Figure 10.25 The formal form and the SQL form of the right outer join for Figure 10.17.<\/p>\n<p class=\"import-Normal\">The output would be<\/p>\n<table>\n<tbody>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\" colspan=\"3\">\n<p class=\"import-Normal\">Squares <strong>\u27d6<\/strong> Cubes<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Number<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Cube<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Square<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">2<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">8<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">4<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">3<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">18<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">9<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">5<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">75<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">NULL<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p class=\"import-Normal\">Figure 10.26 The example output table for the right outer join. Adapted from Fiona Brown\u2019s example. (Corrected to conform with the Third Edition Style Guide.) Source: https:\/\/www.guru99.com\/joins-sql-left-right.html<\/p>\n<p class=\"import-Normal\">Again, all of the Cubes table rows are included in the output plus any matching rows from the Squares table rows. Any \u201cmissing\u201d rows in this table are noted as NULLs.<\/p>\n<h4>Full Outer Join<\/h4>\n<p class=\"import-Normal\">For the full outer join, you could imagine that there are two main tables and we are including all tuples or rows in the output. It seems that we are ignoring the matching condition clause. That is not true. This helps to determine where the NULL entries would appear. Figure 10.27 uses Venn diagrams to illustrate this operation:<\/p>\n<p class=\"import-Normal\"><img decoding=\"async\" src=\"https:\/\/pressbooks.bccampus.ca\/nelson\/wp-content\/uploads\/sites\/2211\/2025\/01\/image4-1.jpeg\" alt=\"image\" width=\"311.733333333333px\" height=\"199.933333333333px\" \/><\/p>\n<p class=\"import-Normal\">Figure 10.27 Venn diagrams illustrating a full outer join. Source of image: https:\/\/www.w3schools.com\/sql\/sql_join_full.asp<sup class=\"import-FootnoteReference\"><a id=\"sdfootnote14anc\" href=\"#sdfootnote14sym\">14<\/a><\/sup><\/p>\n<p class=\"import-Normal\">To see this from a different viewpoint, we will take the table from Figure 10.17.<\/p>\n<p class=\"import-Normal\">We would write the full outer join as<\/p>\n<table>\n<tbody>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\" style=\"text-align: center\"><strong>Formal Expression<\/strong><\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\" style=\"text-align: center\"><strong>SQL Expression<\/strong><\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\" style=\"margin-left: 13.5pt\">Squares <strong>\u27d7<\/strong> Cubes<\/p>\n<p class=\"import-Normal\">\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">SELECT &lt;column names&gt;<\/p>\n<p class=\"import-Normal\">FROM Squares<\/p>\n<p class=\"import-Normal\">FULL OUTER<sup class=\"import-FootnoteReference\"><a id=\"sdfootnote15anc\" href=\"#sdfootnote15sym\">15<\/a><\/sup> JOIN Cubes ON Squares.Number = Cubes.Number<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p class=\"import-Normal\">Figure 10.28 The formal form and the SQL form of the right outer join for Figure 10.17.<\/p>\n<p class=\"import-Normal\">The output would be<\/p>\n<table>\n<tbody>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\" colspan=\"3\">\n<p class=\"import-Normal\">Squares <strong>\u27d7<\/strong> Cubes<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Number<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Square<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Cube<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">2<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">4<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">8<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">3<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">9<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">18<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">4<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">16<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">NULL<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">5<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">NULL<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">75<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p class=\"import-Normal\">Figure 10.29 The example output table for the full outer join. Adapted from Fiona Brown\u2019s example. (Corrected to conform with the Third Edition Style Guide.) Source: https:\/\/www.guru99.com\/joins-sql-left-right.html<\/p>\n<p class=\"import-Normal\">Again, all of the rows from both tables are included in the output with \u201cmissing\u201d fields filled in as NULLs.<\/p>\n<h4>Other Joins<\/h4>\n<p class=\"import-Normal\">The inner join is the most widely used join operation and can be regarded as the default join type. We have explored the theta join, the natural join, and equijoin. These are \u201cshort cut\u201d ways of expressing a desired form of the inner join.<\/p>\n<p class=\"import-Normal\">Outer joins preserve rows with incomplete data. For example, we could see in the output both customers that have ordered something and that have not ordered anything recently.<\/p>\n<p class=\"import-Normal\">Some databases support the <em>self join<\/em>. This is when one table is treated as two tables. W3 schools website has an example where the user is looking for customers that are from the same city. The syntax is a bit odd. See <a class=\"rId12\" href=\"https:\/\/www.w3schools.com\/sql\/sql_join_self.asp\"><span class=\"import-Hyperlink\">https:\/\/www.w3schools.com\/sql\/sql_join_self.asp<\/span><\/a> for this example<\/p>\n<p class=\"import-Normal\">The <em>anti <\/em><em>join<\/em> will return the rows that semi join had rejected. See <a class=\"rId13\" href=\"https:\/\/blog.dailydoseofds.com\/p\/what-are-semi-anti-and-natural-joins\"><span class=\"import-Hyperlink\">https:\/\/blog.dailydoseofds.com\/p\/what-are-semi-anti-and-natural-joins<\/span><\/a> for more information.<\/p>\n<p class=\"import-Normal\">Figure 10.30 shows seven of the possible joins.<\/p>\n<p class=\"import-Normal\"><img decoding=\"async\" src=\"https:\/\/pressbooks.bccampus.ca\/nelson\/wp-content\/uploads\/sites\/2211\/2025\/01\/image5-6.png\" alt=\"image\" width=\"624px\" height=\"440.133333333333px\" \/><\/p>\n<p class=\"import-Normal\">Figure 10.30 Seven join SQL commands with Venn diagrams. Source of image: https:\/\/www.techdoge.in\/2017\/10\/learn-sql-MySql-what-is-join-and-how-to-use-them.html<\/p>\n<h3>Binary Relational Operation: Division<\/h3>\n<p class=\"import-Normal\">The<em> division<\/em> operation is defined to be a relation over the attributes that consists of the set of tuples from R that match the combination of every tuple in S. This abstract definition may be hard to understand. The following are example use cases where the division operator would be useful:<\/p>\n<ul>\n<li>Find suppliers that can provide all parts.<\/li>\n<li>Find all employees who have worked on all projects controlled by one department.<\/li>\n<li>Find the topic that is taught in all courses.<\/li>\n<\/ul>\n<p class=\"import-Normal\">Do not confuse regular algebra subtraction and division. For example:<\/p>\n<p class=\"import-Normal\">10 \/ 2 is similar to 10 \u2013 2 becomes 8 -2 becomes 6 \u2013 2 becomes 4 \u2013 2 becomes 2 \u2013 2, which is subtracting the number 2 five times.<\/p>\n<p class=\"import-Normal\">In relational algebra subtraction, we are looking for all tuples that are present in the first table, but are not in the second table. In relational algebra division, we are looking for something in the first table that has a relationship with every entity in the second table.<\/p>\n<p class=\"import-Normal\">Imagine that you have come to the British Columbia government website that has a list of post-secondary institutions (<a class=\"rId15\" href=\"https:\/\/www2.gov.bc.ca\/gov\/content\/education-training\/post-secondary-education\/find-a-program-or-institution\/find-an-institution\"><span class=\"import-Hyperlink\">https:\/\/www2.gov.bc.ca\/gov\/content\/education-training\/post-secondary-education\/find-a-program-or-institution\/find-an-institution<\/span><\/a>). Behind the page, imagine that there are two database tables. One contains all of the possible academic majors available in British Columbia. The second table contains rows that have the institution\u2019s name and the available academic majors. Figure 10.31 shows an extract from these imaginary database tables.<\/p>\n<table>\n<tbody>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\" style=\"text-align: center\">MajorsInBC<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"background-color: #d9d9d9;border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\" colspan=\"2\">\n<p class=\"import-Normal\" style=\"text-align: center\">InstitutionsAndMajors<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">AvailableMajors<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"background-color: #d9d9d9;border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Institution<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Majors<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Computer Application Training<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"background-color: #d9d9d9;border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">British Columbia Institute of Technology<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Computer Application Training<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Computer Hardware<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"background-color: #d9d9d9;border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">British Columbia Institute of Technology<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Computer Hardware<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Forensic Computing<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"background-color: #d9d9d9;border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">British Columbia Institute of Technology<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Forensic Computing<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Networking and Security<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"background-color: #d9d9d9;border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">British Columbia Institute of Technology<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Networking and Security<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Software Development<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"background-color: #d9d9d9;border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">British Columbia Institute of Technology<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Software Development<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Web Technologies<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"background-color: #d9d9d9;border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">British Columbia Institute of Technology<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Web Technologies<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Computing Studies and Information Systems<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"background-color: #d9d9d9;border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Camosun College<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Marketing<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Web and Mobile Computing<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"background-color: #d9d9d9;border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Camosun College<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Sport Management<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Fine and Applied Arts<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"background-color: #d9d9d9;border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Capilano University<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Fine and Applied Arts<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Global and Community Studies<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"background-color: #d9d9d9;border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Capilano University<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Global and Community Studies<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">General Studies<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"background-color: #d9d9d9;border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Coast Mountain College<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">General Studies<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Marketing<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"background-color: #d9d9d9;border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Coast Mountain College<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Environmental Geoscience Specialization<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Sport Management<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"background-color: #d9d9d9;border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Douglas College<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Computing Studies and Information Systems<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Environmental Geoscience Specialization<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"background-color: #d9d9d9;border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Douglas College<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Web and Mobile Computing<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p class=\"import-Normal\">Figure 10.31 Data drawn from the British Columba education website and from several institutions in British Columbia.<\/p>\n<p class=\"import-Normal\">Figure 10.31 does not list all 25 higher education institutions in British Columbia. Nor does Figure 10.31 list all of the possible majors the sample institutions or the rest of the higher education institutions. Let\u2019s imagine that you wish to explore all web computing programs.<\/p>\n<p class=\"import-Normal\">We could use MajorsInBC \u00f7 InstitutionsAndMajors. The result would be as follows:<\/p>\n<table style=\"width: 478.8pt\">\n<tbody>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\" colspan=\"2\">\n<p class=\"import-Normal\">InstitutionsAndMajors<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">British Columbia Institute of Technology<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Web Technologies<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Douglas College<\/p>\n<\/td>\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\">\n<p class=\"import-Normal\">Web and Mobile Computing<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\" colspan=\"2\">\n<p class=\"import-Normal\">=<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\" colspan=\"2\">\n<p class=\"import-Normal\">MajorsInBC<\/p>\n<\/td>\n<\/tr>\n<tr class=\"TableGrid-R\">\n<td class=\"TableGrid-C\" style=\"border: solid windowtext 0.5pt\" colspan=\"2\">\n<p class=\"import-Normal\">Web<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p class=\"import-Normal\">Figure 10.32 Result of finding institutions in British Columbia with a web major.<sup class=\"import-FootnoteReference\"><a id=\"sdfootnote16anc\" href=\"#sdfootnote16sym\">16<\/a><\/sup><\/p>\n<p class=\"import-Normal\">This contrived example ignored the fact that \u201cweb technologies\u201d and \u201cweb and mobile computing\u201d are different. The problem with this example is that the second table is not normalized.<\/p>\n<p class=\"import-Normal\">Some textbooks and some websites do not address this topic. Most SQL implementations do not support the division operation. So how would division be done in modern relational DBMS?<\/p>\n<p class=\"import-Normal\">The Geeks for Geeks article listed the following ways to implement relational division in SQL:<\/p>\n<ul>\n<li>Method 1: Use cross join and EXCEPT<\/li>\n<li>Method 2: Use correlated subquery and NOT EXISTS<\/li>\n<\/ul>\n<p class=\"import-Normal\">As division can be rendered as a series of subtraction steps, relational algebra can do the same thing:<\/p>\n<ol>\n<li>Generate all combinations by computing the Cartesian product of all possible y values in S with distinct x values in R.<\/li>\n<li>Identify the incomplete combinations. Use the subtract relational operator by subtracting R from the combinations in step 1 in order to find x values not associated with every y.<\/li>\n<li>Subtract the identified x values from all x values to get those associated with every y.<\/li>\n<\/ol>\n<p class=\"import-Normal\">One final note. It is possible to use the regular division operator in SQL<sup class=\"import-FootnoteReference\"><a id=\"sdfootnote17anc\" href=\"#sdfootnote17sym\">17<\/a><\/sup>. An example might be that you wish to output what would be value of dividing in half the current price of products in a table.<\/p>\n<p class=\"import-Normal\" style=\"padding-left: 40px\">SELECT Price, Price \/ 2 AS \u201cHalf Price\u201d<\/p>\n<p class=\"import-Normal\" style=\"padding-left: 40px\">FROM Products;<\/p>\n<p class=\"import-Normal\">This is not the relational algebra division operator.<\/p>\n<h2>Regular Calculus and Relational Calculus<\/h2>\n<p class=\"import-Normal\">Regular calculus is the study of rates of change. Differential calculus is concerned with the rate of change and works with derivatives and differentials. There is great interest in the slope of a line. Integral calculus seeks to find the quantity where the rate of change is known. Integral calculus looks at the space or area under the curve or slope.<\/p>\n<p class=\"import-Normal\">Wolfram MathWorld used the word \u201canalysis\u201d as another term for the word \u201ccalculus<sup class=\"import-FootnoteReference\"><a id=\"sdfootnote18anc\" href=\"#sdfootnote18sym\">18<\/a><\/sup>.\u201d Thomas Connoly and Carolyn Begg pointed out that relational calculus is closer to predicate calculus.<\/p>\n<p class=\"import-Normal\">A <em>predicate<\/em> is an expression of one or more variables for a certain domain. Consider the following:<\/p>\n<p class=\"import-Normal\" style=\"padding-left: 40px\">Douglas College is a public college.<\/p>\n<p class=\"import-Normal\">Predicate calculus would make the following statements:<\/p>\n<ul>\n<li>\u201c\u2026 is a public college\u201d is a predicate and \u201cDouglas College\u201d is the subject.<\/li>\n<li>Let \u201cDouglas College\u201d be denoted as \u201cx\u201d and \u201c..is a public college\u201d be denoted as Predicate P. Then we can write\n<ul>\n<li>P(x)<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p class=\"import-Normal\">A predicate must have at least one object that is associated with the predicate. \u201cDouglas College\u201d is the required object.<\/p>\n<p class=\"import-Normal\">We will not go any deeper on the topic of predicate calculus. You can learn more about this topic by visiting <a class=\"rId16\" href=\"https:\/\/www.tutorialspoint.com\/the-predicate-calculus\"><span class=\"import-Hyperlink\">https:\/\/www.tutorialspoint.com\/the-predicate-calculus<\/span><\/a><\/p>\n<p class=\"import-Normal\"><em>Relational calculus<\/em> specifies <strong>what <\/strong>is to be retrieved whereas relational algebra states <strong>how<\/strong> to obtain the results. In relational calculus, we work with tuple relational calculus and with domain relational calculus.<\/p>\n<h3>Tuple Relational Calculus<\/h3>\n<p class=\"import-Normal\">In <em>tuple relational calculus<\/em>, we wish to obtain those tuples that are true for a certain predicate. Using the above predicate example (\u201cDouglas College is a public college.\u201d), we could use the following shorthand:<\/p>\n<p class=\"import-Normal\" style=\"padding-left: 40px\">PublicCollege(S)<\/p>\n<p class=\"import-Normal\" style=\"padding-left: 40px\">Where the tuple variable S would be the range of permitted values.<\/p>\n<p class=\"import-Normal\">So we could have the following query:<\/p>\n<p class=\"import-Normal\" style=\"padding-left: 40px\">Find the set of all tuples S such that F(S) is true<\/p>\n<p class=\"import-Normal\" style=\"padding-left: 80px\">{S | F(S)|<\/p>\n<p class=\"import-Normal\">Our S could be all public colleges in British Columbia, or in Canada, or in North America, or in the world. In this example, S would not contain high schools or people\u2019s names or animal names.<\/p>\n<p class=\"import-Normal\">In the above shorthand expression, the letter \u201cF\u201d is called a formula or in pure mathematical logic, a well-formed formula or wff.<\/p>\n<p class=\"import-Normal\">Imagine that we are working with a database table with the names of Staffers and that contains the following columns:<\/p>\n<ul>\n<li>ID<\/li>\n<li>FirstName<\/li>\n<li>LastName<\/li>\n<li>Position<\/li>\n<li>Gender<\/li>\n<li>DoB<\/li>\n<li>Salary<\/li>\n<li>BranchNumber<\/li>\n<\/ul>\n<p class=\"import-Normal\">We wish to express in relational calculus the following:<\/p>\n<p class=\"import-Normal\" style=\"margin-left: 36pt\">Find the ID, FirstName, LastName, Position, Gender, DoB, Salary, and BranchNumber for individuals earning more than $10,000.<\/p>\n<p class=\"import-Normal\">This query would appear as follows:<\/p>\n<p class=\"import-Normal\" style=\"padding-left: 40px\">{S | Staffers(s) <strong>\u2227<\/strong><sup class=\"import-FootnoteReference\"><strong><a id=\"sdfootnote19anc\" href=\"#sdfootnote19sym\">19<\/a><\/strong><\/sup> S.Salary &gt; 10000}<\/p>\n<p class=\"import-Normal\">The letter \u201cS\u201d between the left curved brace and the pipe symbol means all columns. The <strong>\u2227<\/strong> is the logical conjunction and may be read as \u201cand.\u201d This is the Boolean AND operator. A tuple is collected if the row exists with a Salary greater than $10,000. In this example, we are assuming that the Staffers table has only columns for ID, FirstName, LastName, Position, Gender, DoB, Salary, and BranchNumber. If we wish to select a subset such as the Salary column, then we would need to modify the last expression as follows:<\/p>\n<p class=\"import-Normal\" style=\"margin-left: 36pt\">{S.Salary | Staffers(s) <strong>\u2227<\/strong> S.Salary &gt; 10000}<\/p>\n<p class=\"import-Normal\">Predicate calculus uses two quantifiers. Relational calculus uses these same two quantifiers.<\/p>\n<ul>\n<li>The <em>existential quantifier<\/em> <a class=\"rId17\" title=\"\u2203\" href=\"https:\/\/en.wikipedia.org\/wiki\/%E2%88%83\"><strong class=\"import-Hyperlink\">\u2203<\/strong><\/a><sup class=\"import-FootnoteReference\"><strong><a id=\"sdfootnote20anc\" href=\"#sdfootnote20sym\">20<\/a><\/strong><\/sup> means \u201cthere exists\u201d. At least one instance or tuple is true for the statement.<\/li>\n<li>The <em>universal quantifier<\/em> <a class=\"rId18\" title=\"\u2200\" href=\"https:\/\/en.wikipedia.org\/wiki\/%E2%88%80\"><span class=\"import-Hyperlink\">\u2200<\/span><\/a><sup class=\"import-FootnoteReference\"><a id=\"sdfootnote21anc\" href=\"#sdfootnote21sym\">21<\/a><\/sup> means \u201cfor all.\u201d All tuples must be true for the statement.<\/li>\n<\/ul>\n<p class=\"import-Normal\">Let\u2019s use Douglas College as our example and express two statements in relational calculus:<\/p>\n<ul>\n<li>There exists a Course (C) tuple that has the same ID (CourseID) as the CourseID of the current Student tuple, S, and is located in New Westminster.\n<ul>\n<li>Student(S) <strong>\u2227<\/strong> (<a class=\"rId19\" title=\"\u2203\" href=\"https:\/\/en.wikipedia.org\/wiki\/%E2%88%83\"><strong class=\"import-Hyperlink\">\u2203<\/strong><\/a>C) (Course(C) <strong>\u2227<\/strong> (C.ID = S.CourseID) <strong>\u2227<\/strong> C.City = \u201cNew Westminster\u201d<\/li>\n<\/ul>\n<\/li>\n<li>For all Computing Studies and Information Systems courses (C), the city is New Westminster.\n<ul>\n<li>(<a class=\"rId20\" title=\"\u2200\" href=\"https:\/\/en.wikipedia.org\/wiki\/%E2%88%80\"><span class=\"import-Hyperlink\">\u2200<\/span><\/a>C) (C.City = \u201cNew Westminster\u201d)<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p class=\"import-Normal\">Negations could be used. So the last expression could be written as<\/p>\n<ul>\n<li style=\"list-style-type: none\">\n<ul>\n<li>(<a class=\"rId21\" title=\"\u2200\" href=\"https:\/\/en.wikipedia.org\/wiki\/%E2%88%80\"><span class=\"import-Hyperlink\">\u2200<\/span><\/a>C) (C.City \u2260 \u201cCoquitlam<sup class=\"import-FootnoteReference\"><a id=\"sdfootnote22anc\" href=\"#sdfootnote22sym\">22<\/a><\/sup>\u201d)<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p class=\"import-Normal\">Recall that the intersection binary relational operator could be rewritten as a series of union and set differences, so relational calculus statements could be expressed in other ways. De Morgan\u2019s laws can be used. The following is another version of the last expression:<\/p>\n<ul>\n<li>~(<a class=\"rId22\" title=\"\u2203\" href=\"https:\/\/en.wikipedia.org\/wiki\/%E2%88%83\"><strong class=\"import-Hyperlink\">\u2203<\/strong><\/a>C) (C.City = \u201cCoquitlam\u201d)<\/li>\n<\/ul>\n<p class=\"import-Normal\">Recall that in a Boolean environment, you could negate an AND statement by negating each element and changing the AND to become an OR:<\/p>\n<p class=\"import-Normal\" style=\"padding-left: 40px\">~(A AND B) is the same thing as ~ A OR ~B<sup class=\"import-FootnoteReference\"><a id=\"sdfootnote23anc\" href=\"#sdfootnote23sym\">23<\/a><\/sup><\/p>\n<p class=\"import-Normal\">This behavior is true in relational calculus. Notice the change in from <a class=\"rId23\" title=\"\u2200\" href=\"https:\/\/en.wikipedia.org\/wiki\/%E2%88%80\"><span class=\"import-Hyperlink\">\u2200<\/span><\/a> to <a class=\"rId24\" title=\"\u2203\" href=\"https:\/\/en.wikipedia.org\/wiki\/%E2%88%83\"><strong class=\"import-Hyperlink\">\u2203<\/strong><\/a>.<\/p>\n<p class=\"import-Normal\">You need to be careful, because you could create an unsafe expression. Look at the following:<\/p>\n<ul>\n<li>The set of all tuples that are not in the Student relation:\n<ul>\n<li>{S | ~ Student(S)}<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p class=\"import-Normal\">This is <em>unsafe<\/em>, because this would generate a huge number of tuples. To avoid this, we need to add a restriction that all values that appear in the result must be values in the <em>domain<\/em> of the expression E, donated as dom (E). Or to put it differently, the domain of E is the set of all values that appear explicitly in E or that appear in or more relations whose names appear in E. In the last relational calculus example, the domain of the expression is the set of all values that appear in the Student relation. So an expression is <em>safe<\/em> if all values that appear in the result are values drawn from the domain of the expression. All of the previous examples of tuple relational calculus are safe.<\/p>\n<h3>Domain Relational Calculus<\/h3>\n<p class=\"import-Normal\"><em>Domain relational calculus<\/em> uses variables, but the variables come the domains of the attributes instead from the tuples of relations. An expression in domain relational calculus has the following general form:<\/p>\n<p class=\"import-Normal\" style=\"padding-left: 40px\">{ d<sub>1<\/sub>, d<sub>2<\/sub>, \u2026, d<sub>n<\/sub> | F(d<sub>1<\/sub>, d<sub>2<\/sub>, \u2026, d<sub>m<\/sub>) } m \u2265 n<\/p>\n<p class=\"import-Normal\" style=\"padding-left: 80px\">Where d<sub>1<\/sub>, d<sub>2<\/sub>, \u2026, d<sub>n<\/sub><sub> and <\/sub>d<sub>1<\/sub>, d<sub>2<\/sub>, \u2026, d<sub>m <\/sub>represent the domain variables<\/p>\n<p class=\"import-Normal\" style=\"padding-left: 80px\">Where F(d<sub>1<\/sub>, d<sub>2<\/sub>, \u2026, d<sub>m<\/sub>) represents a formula composed of atoms and an atom has the one of the following forms:<\/p>\n<ul>\n<li style=\"list-style-type: none\">\n<ul>\n<li style=\"list-style-type: none\">\n<ul>\n<li>R(d<sub>1<\/sub>, d<sub>2<\/sub>, \u2026, d<sub>n<\/sub>), where R is a relation of degree n and each d<sub>i<\/sub> is a domain variable.<\/li>\n<li>d<sub>i<\/sub> <strong>\u03b8<\/strong> d<sub>j<\/sub>, where d<sub>i<\/sub> and d<sub>j<\/sub> are domain variables and <strong>\u03b8<\/strong> is one of the comparison operator (&lt;, \u2264, &gt;, \u2265, =, \u2260); the domains d<sub>i<\/sub> and d<sub>j<\/sub> must have members that can be compared by <strong>\u03b8<\/strong><strong>.<\/strong><\/li>\n<li>d<sub>i<\/sub> <strong>\u03b8<\/strong> c,, where d<sub>i<\/sub> is a domain variable, c is a constant from the domain of d<sub>i<\/sub>, and <strong>\u03b8<\/strong> is one of the comparison operators.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p class=\"import-Normal\">The word \u201catom\u201d is used, because atoms are the building blocks for more complex formulae.<\/p>\n<p class=\"import-Normal\">Recall the relational calculus example:<\/p>\n<p class=\"import-Normal\" style=\"margin-left: 36pt\">Find the ID, FirstName, LastName, Position, Gender, DoB, Salary, and BranchNumber for individuals earning more than $10,000.<\/p>\n<p class=\"import-Normal\">That query appeared as follows:<\/p>\n<p class=\"import-Normal\" style=\"padding-left: 40px\">{S | Staffers(s) <strong>\u2227<\/strong> S.Salary &gt; 10000}<\/p>\n<p class=\"import-Normal\">To demonstrate how complex a domain relational calculus expression can be, we will add the restriction of finding managers that earn more than $10,000. So this query would appear as follows:<\/p>\n<p class=\"import-Normal\" style=\"padding-left: 40px\">{FirstName, LastName | <a class=\"rId25\" title=\"\u2203\" href=\"https:\/\/en.wikipedia.org\/wiki\/%E2%88%83\"><strong class=\"import-Hyperlink\">\u2203<\/strong><\/a>ID, Position, Gender, DoB, Salary, BranchNumber) (Staffers (ID, FirstName, LastName, Position, Gender, DoB, Salary, BranchNumber) <strong>\u2227<\/strong> Position = \u201cManager\u201d <strong>\u2227<\/strong> Salary &gt; 10000)}<\/p>\n<p class=\"import-Normal\">The condition (Staffers (ID, FirstName, LastName, Position, Gender, DoB, Salary, BranchNumber) ensures that the domain variables are restricted to the attributes of the same tuple. Since we used this condition, we could use the shortcut of \u201cPosition = Manager\u201d instead of \u201cStaff.Position = \u201cManager.\u201d This approach has an interesting benefit. We do not need to use the existential quantifier <a class=\"rId26\" title=\"\u2203\" href=\"https:\/\/en.wikipedia.org\/wiki\/%E2%88%83\"><strong class=\"import-Hyperlink\">\u2203<\/strong><\/a>. Another benefit is that these queries are safe.<\/p>\n<p class=\"import-Normal\">Domain relational calculus was presented for completeness. We will not go any further.<\/p>\n<h3>Recapping Relational Algebra and Relational Calculus<\/h3>\n<p class=\"import-Normal\">Relational calculus specifies <strong>what <\/strong>is to be retried whereas relational algebra states <strong>how<\/strong> to obtain the results. For every relational algebra expression, there is an equivalent expression in relational calculus. And for every tuple relational calculus or domain relational calculus expression there is an equivalent relational algebra expression.<\/p>\n<p class=\"import-Normal\">We can use the relational algebra to rewrite a query to be more efficient.<\/p>\n<p class=\"import-Normal\">Relational algebra and relational calculus can be used to write statements as a common language (a lingua franca) between database developers. Consider the command for obtaining the first three rows from a database table:<\/p>\n<ul>\n<li>Microsoft: SELECT TOP 3 * FROM Customers;<\/li>\n<li>MySQL: SELECT * FROM Customers Limit 3;<\/li>\n<li>Oracle: SELECT * FROM Customers where rownum &lt;= 3;<\/li>\n<\/ul>\n<p class=\"import-Normal\"><strong>\u00a0<\/strong><\/p>\n<h2>Key Terms<\/h2>\n<p class=\"import-Normal\"><strong>anti<\/strong><strong> join<\/strong>: This will return the rows that semi join had rejected.<\/p>\n<p class=\"import-Normal\"><strong>atom<\/strong><strong>:<\/strong> This is a building block for more complex formulae in domain relational calculus.<\/p>\n<p class=\"import-Normal\"><strong>binary<\/strong><strong>: <\/strong>The operation involves two database tables.<\/p>\n<p class=\"import-Normal\"><strong>Cartesian product<\/strong><strong>:<\/strong> This is an operation from set theory. This is also known as \u201ccross product.\u201d If we drop the requirement that a relation must be union compatible, then you could have an output that is larger than either relation. The result is a new element by combining every member tuple from one relation set with every member tuple from the other relation set.<\/p>\n<p class=\"import-Normal\"><strong>c<\/strong><strong>ommutative<\/strong><strong>: <\/strong>The sequence of actions could be changed and the answer would still be the same.<\/p>\n<p class=\"import-Normal\"><strong>division<\/strong><strong>:<\/strong> This operation is defined to be a relation over the attributes that consists of the set of tuples from R that match the combination of every tuple in S.<\/p>\n<p class=\"import-Normal\"><strong>e<\/strong><strong>quijoin:<\/strong> This is like a theta join in that the equijoin operation pulls from two tables based on a condition represented by the Greek letter theta (<strong>\u03b8<\/strong>). But <strong>\u03b8<\/strong> is the equal symbol (=).<\/p>\n<p class=\"import-Normal\"><strong>existential quantifier<\/strong> <a class=\"rId27\" title=\"\u2203\" href=\"https:\/\/en.wikipedia.org\/wiki\/%E2%88%83\"><strong class=\"import-Hyperlink\">\u2203<\/strong><\/a><strong>: <\/strong>This means \u201cthere exists\u201d at least one instance or tuple that is true for the statement.<\/p>\n<p class=\"import-Normal\"><strong>i<\/strong><strong>ntersection \u2229<\/strong><strong>:<\/strong> This is a set operation that does not have a counterpart in regular algebra. It extracts what is common to two database tables based on a conditional.<\/p>\n<p class=\"import-Normal\"><strong>j<\/strong><strong>oin<\/strong> <strong>\u22c8<\/strong><strong>:<\/strong> This is an operation from set theory. A way of pulling from two tables. This was added to the set operators.<\/p>\n<p class=\"import-Normal\"><strong>natural join<\/strong><strong>:<\/strong> This is like a theta join that pulls from two tables, but the extra column is not included in the output and the ON key word is not used.<\/p>\n<p class=\"import-Normal\"><strong>operands<\/strong><strong>:<\/strong> In regular algebra, these are variables or values used in an expression. In relational algebra, these are relations or variables that represent relations.<\/p>\n<p class=\"import-Normal\"><strong>o<\/strong><strong>perators<\/strong><strong>:<\/strong> In regular algebra, these are symbols that denote what will be done to the regular algebra operands. In relational algebra, these are the common actions that we need to do with relations in a database.<\/p>\n<p class=\"import-Normal\"><strong>o<\/strong><strong>uter join<\/strong>: This will return rows from two tables even if there are no matches in one of the tables. An outer join can be divided into three sub types:<\/p>\n<ul>\n<li>Left outer join (R \u27d5 S): Everything from left plus any matching rows on the left with the right table plus nulls for any missing rows.<\/li>\n<li>Right outer join (R \u27d6 S): Everything from right plus any matching rows on the right with the left table plus nulls for any missing rows<\/li>\n<li>Full outer join (R \u27d7 S): Everything from both tables plus nulls for any missing fields.<\/li>\n<\/ul>\n<p class=\"import-Normal\"><strong>predicate<\/strong><strong>: <\/strong>This is an expression of one or more variables for a certain domain. A predicate must have at least one object that is associated with the predicate.<\/p>\n<p class=\"import-Normal\"><strong>projection \u03c0<\/strong><strong> (The lower case Greek letter pi): <\/strong>This selects a subset of the available columns. This was added to the set operators.<\/p>\n<p class=\"import-Normal\"><strong>relational algebra<\/strong><strong>:<\/strong> This collects instances of relations as input and gives occurrences of relations as outputs. The expressions explain how to execute a query. The expressions are independent of any SQL system.<\/p>\n<p class=\"import-Normal\"><strong>relational calculus<\/strong>: This specifies <strong>what <\/strong>is to be retrieved whereas relational algebra states<strong> how<\/strong> to obtain the results. In relational calculus, we work with tuple relational calculus and with domain relational calculus.<\/p>\n<ul>\n<li>Tuple relational calculus: This seeks to obtain those tuples that are true for a certain predicate. The variables come from the tuples of the relations.<\/li>\n<li>Domain relational calculus: This uses variables come from the domains of the attributes.<\/li>\n<\/ul>\n<p class=\"import-Normal\"><strong>r<\/strong><strong>enaming<\/strong> <strong> \u03f8<\/strong><strong> (The lower case Greek letter rho)<\/strong><strong>: <\/strong>This renames the output columns. This was added to the set operators.<\/p>\n<p class=\"import-Normal\"><strong>safe<\/strong>: The expression draws upon members of a defined domain.<\/p>\n<p class=\"import-Normal\"><strong>self join<\/strong><strong>:<\/strong> This is when one table is treated as two tables.<\/p>\n<p class=\"import-Normal\"><strong>s<\/strong><strong>election \u03c3<\/strong><strong> (The lower case Greek letter sigma<\/strong><strong>):<\/strong> A way of selecting tuples that satisfies a selection condition. This was added to the set operators. Do not confuse this word with the SQL key word \u201cSELECT,\u201d which lists out the desired columns in the output.<\/p>\n<p class=\"import-Normal\"><strong>s<\/strong><strong>electivity of the condition<\/strong>: The fraction of tuples selected by a selection condition.<\/p>\n<p class=\"import-Normal\"><strong>s<\/strong><strong>emijoin<\/strong>: In a left outer join, you would have the desired columns from both tables. Nulls would appear in the right hand table for missing values. A semijoin would drop the right-hand table\u2019s columns. The result would be the tuples that have a match in the second table.<\/p>\n<p class=\"import-Normal\"><strong>set difference<\/strong><strong>:<\/strong> This is from set theory. These are the tuples that are present in one relation, but not present in a second relation. We write this as R \u2013 S, which states that this includes all tuples that are in R, but are not in S. The two relations must be union compatibility or type compatibility.<\/p>\n<p class=\"import-Normal\"><strong>set operations<\/strong><strong>: <\/strong>These are operations drawn from mathematical set theory. These are union, intersection, set difference, and Cartesian product.<\/p>\n<p class=\"import-Normal\"><strong>t<\/strong><strong>heta <\/strong><strong>join<\/strong> <strong>\u03b8<\/strong> <strong>(The lower case Greek letter <\/strong><strong>theta):<\/strong> This pulls from two tables based on a condition represented by the Greek letter theta (<strong>\u03b8<\/strong>). <strong>\u03b8<\/strong> could be any one of the comparison operators.<\/p>\n<p class=\"import-Normal\"><strong>type compatibility<\/strong><strong>:<\/strong> This states that the two database tables must have the same degree and the same domain. This is the same concept as is \u201cunion compatibility.\u201d<\/p>\n<p class=\"import-Normal\"><strong>u<\/strong><strong>n<\/strong><strong>ary<\/strong><strong>: <\/strong>This means we are working with one relation or with one database table.<\/p>\n<p class=\"import-Normal\"><strong>union<\/strong> <span lang=\"pt-BR\" xml:lang=\"pt-BR\">\u222a<\/span>: This produces the tuples that are in either Result1 or Result2 or both while removing any duplicates. In the relational database world, the two sets of tuples must be of the same type (union compatibility or type compatibility).<\/p>\n<p class=\"import-Normal\"><strong>union compatibility<\/strong><strong>:<\/strong> This states that the two database tables must have the same degree and the same domain. This is the same concept as is \u201ctype compatibility.\u201d<\/p>\n<p class=\"import-Normal\"><strong>universal quantifier<\/strong> <a class=\"rId28\" title=\"\u2200\" href=\"https:\/\/en.wikipedia.org\/wiki\/%E2%88%80\"><span class=\"import-Hyperlink\">\u2200<\/span><\/a>: This means \u201cfor all.\u201d All tuples must be true for the statement.<\/p>\n<p class=\"import-Normal\"><strong>un<\/strong><strong>safe<\/strong>: The expression draws upon members outside of a defined domain.<\/p>\n<h2>Exercises<\/h2>\n<p class=\"import-Normal\" style=\"margin-left: 18pt\">1. Explain what is the union operator and the SQL union action. Provide an example of the relational algebra expression and provide an example of the common SQL command. [CS2013 IM\/RD 3, IM\/RD 4; IT2017 ITE-IMA-05a.]<\/p>\n<p class=\"import-Normal\" style=\"margin-left: 18pt\">2. Explain what is the intersection operator. Provide an example of the relational algebra expression and provide an example of the common SQL command. [CS2013 IM\/RD 3, IM\/RD 4; IT2017 ITE-IMA-05a.]<\/p>\n<p class=\"import-Normal\" style=\"margin-left: 18pt\">3. Explain what is the difference operator. Provide an example of the relational algebra expression. Research your selected DBMS and find out if it supports the set difference operator. [CS2013 IM\/RD 3, IM\/RD 4; IT2017 ITE-IMA-05a.]<\/p>\n<p class=\"import-Normal\" style=\"margin-left: 18pt\">4. Explain what is the Cartesian product operator. Provide an informal example of when you might want to use the Cartesian product operator. [CS2013 IM\/RD 3, IM\/RD 4.]<\/p>\n<p class=\"import-Normal\" style=\"margin-left: 18pt\">5. Explain what is the select operator and the SELECT key word. Provide an example of the relational algebra expression and provide an example of the common SQL command. [CS2013 IM\/RD 3, IM\/RD 4; IT2017 ITE-IMA-05a.]<\/p>\n<p class=\"import-Normal\" style=\"margin-left: 18pt\">6. Explain what is the project operator and the SELECT key word. Provide an example of the relational algebra expression and provide an example of the common SQL command. [CS2013 IM\/RD 3, IM\/RD 4; IT2017 ITE-IMA-05a.]<\/p>\n<p class=\"import-Normal\" style=\"margin-left: 18pt\">7. Explain what is the join operator. Experts have different lists of the specialized join operators. List three joins that will provide tuples that satisfies only the conditional. List three joins that will include tuples with missing data. Provide an example of an inner join and provide an example of an outer join. Be sure to include both the formal form and the SQL form. There are 11 parts to this question. [CS2013 IM\/RD 3, IM\/RD 4; IT2017 ITE-IMA-05a.]<\/p>\n<p class=\"import-Normal\" style=\"margin-left: 18pt\">8. Explain what is the relational algebra division operator. Provide an informal example. [CS2013 IM\/RD 3, IM\/RD 4.]<\/p>\n<p class=\"import-Normal\" style=\"margin-left: 18pt\">9. Explain what is the natural join relational operator. Provide an example of the relational algebra expression and provide an example of the common SQL command. [IT2017 ITE-IMA-05a.]<\/p>\n<p class=\"import-Normal\" style=\"margin-left: 18pt\">10. Write queries in the tuple relational calculus for the following:<\/p>\n<p class=\"import-Normal\" style=\"margin-left: 18pt;padding-left: 40px\">a. List all hotels<\/p>\n<p class=\"import-Normal\" style=\"margin-left: 18pt;text-indent: 18pt\">b. List all single rooms with a price below $200 per night.<\/p>\n<p class=\"import-Normal\" style=\"margin-left: 18pt;text-indent: 18pt\">c. List the names and cities of all guests.<\/p>\n<p class=\"import-Normal\" style=\"margin-left: 18pt;text-indent: 18pt\">d. List the price and type of all rooms at the Greenbrier Hotel.<\/p>\n<h2>A Running Project<\/h2>\n<p class=\"import-Normal\">Continue to work on your project.<\/p>\n<h2>Attribution<\/h2>\n<p class=\"import-Normal\">This chapter of <em>Database Design<\/em> is a brand-new addition.<\/p>\n<p class=\"import-Normal\"><a id=\"_Hlk165870885\"><\/a>This chapter drew from many sources.<\/p>\n<h2>Image Attributions<\/h2>\n<p class=\"import-Normal\">No second edition images were used.<\/p>\n<h2>References<\/h2>\n<p class=\"import-Normal\">Fiona Brown. \u201cDBMS Joins: Inner, THETA, Outer, Equi Types of Join Operations,\u201d Guru99, June 28, 2024. <a class=\"rId29\" href=\"https:\/\/www.guru99.com\/joins-sql-left-right.html\"><span class=\"import-Hyperlink\">https:\/\/www.guru99.com\/joins-sql-left-right.html<\/span><\/a><\/p>\n<p class=\"import-Normal\">Thomas Connolly and Carolyn Begg<em>. Database Systems<\/em><em>: A<\/em><em> Practical Approach to Design, Implementation, and Management<\/em>, Addison Wesley, 2002, page 88.<\/p>\n<p class=\"import-Normal\">\u201cSQL | Division,\u201d Geeks for Geeks, July 3, 2024. <a class=\"rId30\" href=\"https:\/\/www.geeksforgeeks.org\/sql-division\/\"><span class=\"import-Hyperlink\">https:\/\/www.geeksforgeeks.org\/sql-division\/<\/span><\/a><\/p>\n<div id=\"sdfootnote1sym\"><a href=\"#sdfootnote1anc\">1<\/a> These are topics that are covered in greater detail in a discrete mathematics course. The Computing Accreditation Commission of the ABET require that some computing programs cover discrete mathematics. Bachelor computer science programs have at least 15 academic semester hours of mathematics and one of the courses must be discrete mathematics. Bachelor cybersecurity programs must have at least 6 academic semester hours of mathematics and one of the courses must be discrete mathematics. Bachelor information technology programs must have at least 6 academic semester hours of mathematics and one of the courses must be discrete mathematics. For more information see https:\/\/www.abet.org\/accreditation\/accreditation-criteria\/criteria-for-accrediting-computing-programs-2024-2025\/The Engineering Accreditation Commission of the ABET requires the various programs to have mathematics with the \u201cmathematical sophistication at least equivalent to that of introductory calculus.\u201d Discrete mathematics would satisfy this requirement. Cybersecurity Engineering programs must have a course in discrete mathematics. Software engineering programs must have a course in discrete mathematics. For more information, see https:\/\/www.abet.org\/accreditation\/accreditation-criteria\/criteria-for-accrediting-engineering-programs-2024-2025\/<\/div>\n<div id=\"sdfootnote2sym\"><a href=\"#sdfootnote2anc\">2<\/a> The Greek letters have been used for a long time.<\/div>\n<div id=\"sdfootnote3sym\"><a href=\"#sdfootnote3anc\">3<\/a> In the chapter on SQL commands, we did not address this topic. This will be addressed in another chapter. This is different from using the key word AS for renaming a column in the output.<\/div>\n<div id=\"sdfootnote4sym\"><a href=\"#sdfootnote4anc\">4<\/a> Recall that the term degree refers to the number of columns in a table.<\/div>\n<div id=\"sdfootnote5sym\"><a href=\"#sdfootnote5anc\">5<\/a> Thomas Connolly and Carolyn Begg wrote this as \u201cEquijon.\u201d Fiona Brown wrote this as \u201cEQUI Join.\u201d<\/div>\n<div id=\"sdfootnote6sym\"><a href=\"#sdfootnote6anc\">6<\/a> Fiona Brown used the first two letters from the alphabet and she placed the Greek letter as a subscript.Thomas Connolly and Carolyn Begg used \u201cR\u201d and \u201cS.\u201d They used the letter \u201cF\u201d in the subscript, which stands for the predicate from the Cartesian product of R and S. In their explanation, they wrote \u201cThe predicate F is of the form R.a, <b>\u03b8<\/b>, S.b, where <b>\u03b8<\/b> may be one of the comparison operators (&lt;, \u2264, &gt;, \u2265, =, \u2260).Fiona Brown\u2019s explanation was easier to understand than the very formal Thomas Connolly and Carolyn Beet explanation.<\/div>\n<div id=\"sdfootnote7sym\"><a href=\"#sdfootnote7anc\">7<\/a> Again, Fiona Brown used the first two letters from the alphabet. And she wrote the column names a lower case letter and with a space between the word \u201ccolumn\u201d and the number.<\/div>\n<div id=\"sdfootnote8sym\"><a href=\"#sdfootnote8anc\">8<\/a> Fiona Brown used the theta expression as the table name. A SQL environment might use a generic name for the column label.<\/div>\n<div id=\"sdfootnote9sym\"><a href=\"#sdfootnote9anc\">9<\/a> Fiona Brown used <b>A<\/b><b> <\/b><b>\u27d5<\/b>B.ThomasConnollyandCarolynBeggwrotethisas(RS).Theactualsymbolusedintheirtextbookhadlongerlinesontheleftside\u2014almostlikeacombinationofthesupersetsymbol(\u2283)(U+2283)ontheleftsidewiththejoinsymbol(\u22c8).TheactualleftouterjoinUnicodesymbolsisU+27D5.<b> B. <\/b>masConnollyandCarolynBeggwrotethisas(RS).Theactualsymbolusedintheirtextbookhadlongerlinesontheleftside\u2014almostlikeacombinationofthesupersetsymbol(\u2283)(U+2283)ontheleftsidewiththejoinsymbol(\u22c8).TheactualleftouterjoinUnicodesymbolsisU+27D5.<b> <\/b>asConnollyandCarolynBeggwrotethisas<b>(<\/b><b>R<\/b>S).Theactualsymbolusedintheirtextbookhadlongerlinesontheleftside\u2014almostlikeacombinationofthesupersetsymbol(\u2283)(U+2283)ontheleftsidewiththejoinsymbol(\u22c8).TheactualleftouterjoinUnicodesymbolsisU+27D5.<b> <\/b>).Theactualsymbolusedintheirtextbookhadlongerlinesontheleftside\u2014almostlikeacombinationofthesupersetsymbol(\u2283)(U+2283)ontheleftsidewiththejoinsymbol(\u22c8).TheactualleftouterjoinUnicodesymbolsisU+27D5.<b>\u27d5<\/b>heactualsymbolusedintheirtextbookhadlongerlinesontheleftside\u2014almostlikeacombinationofthesupersetsymbol(\u2283)(U+2283)ontheleftsidewiththejoinsymbol(\u22c8).TheactualleftouterjoinUnicodesymbolsisU+27D5.<b> S<\/b>actualsymbolusedintheirtextbookhadlongerlinesontheleftside\u2014almostlikeacombinationofthesupersetsymbol(\u2283<b>)<\/b>(U+2283)ontheleftsidewiththejoinsymbol(\u22c8).TheactualleftouterjoinUnicodesymbolsisU+27D5.<\/div>\n<div id=\"sdfootnote10sym\"><a href=\"#sdfootnote10anc\">10<\/a> Fiona Brown used <b>A<\/b><b> <\/b><b>\u27d6<\/b>B.ThomasConnollyandCarolynBeggwrotethisas(RS).Theactualsymbolusedintheirtextbookhadlongerlinesontherightside\u2014almostlikeacombinationofthesubsetsymbol(\u2282)(U+2282)ontherightsidewiththejoinsymbol(\u22c8).TheactualrightouterjoinUnicodesymbolisU+27D6.<b> B. <\/b>masConnollyandCarolynBeggwrotethisas(RS).Theactualsymbolusedintheirtextbookhadlongerlinesontherightside\u2014almostlikeacombinationofthesubsetsymbol(\u2282)(U+2282)ontherightsidewiththejoinsymbol(\u22c8).TheactualrightouterjoinUnicodesymbolisU+27D6.<b> <\/b>asConnollyandCarolynBeggwrotethisas<b>(<\/b><b>R<\/b>S).Theactualsymbolusedintheirtextbookhadlongerlinesontherightside\u2014almostlikeacombinationofthesubsetsymbol(\u2282)(U+2282)ontherightsidewiththejoinsymbol(\u22c8).TheactualrightouterjoinUnicodesymbolisU+27D6.<b> <\/b>).Theactualsymbolusedintheirtextbookhadlongerlinesontherightside\u2014almostlikeacombinationofthesubsetsymbol(\u2282)(U+2282)ontherightsidewiththejoinsymbol(\u22c8).TheactualrightouterjoinUnicodesymbolisU+27D6.<b>\u27d6<\/b>heactualsymbolusedintheirtextbookhadlongerlinesontherightside\u2014almostlikeacombinationofthesubsetsymbol(\u2282)(U+2282)ontherightsidewiththejoinsymbol(\u22c8).TheactualrightouterjoinUnicodesymbolisU+27D6.<b> <\/b>eactualsymbolusedintheirtextbookhadlongerlinesontherightside\u2014almostlikeacombinationofthesubsetsymbol(\u2282)(U+2282)ontherightsidewiththejoinsymbol(\u22c8).TheactualrightouterjoinUnicodesymbolisU+27D6.<b>S<\/b>actualsymbolusedintheirtextbookhadlongerlinesontherightside\u2014almostlikeacombinationofthesubsetsymbol(\u2282<b>)<\/b>(U+2282)ontherightsidewiththejoinsymbol(\u22c8).TheactualrightouterjoinUnicodesymbolisU+27D6.<\/div>\n<div id=\"sdfootnote11sym\"><a href=\"#sdfootnote11anc\">11<\/a> Fiona Brown used <b>A<\/b><b> <\/b><b>\u27d7<\/b>B.ThomasConnollyandCarolynBeggmentionedfullouterjoins,butdidnotillustratethisjoinliketheydidfortheothertwoouterjoins.TheactualfullouterjoinUnicodeisU+27D7.<b> <\/b>.ThomasConnollyandCarolynBeggmentionedfullouterjoins,butdidnotillustratethisjoinliketheydidfortheothertwoouterjoins.TheactualfullouterjoinUnicodeisU+27D7.<b>B. <\/b>masConnollyandCarolynBeggmentionedfullouterjoins,butdidnotillustratethisjoinliketheydidfortheothertwoouterjoins.TheactualfullouterjoinUnicodeisU+27D7.<\/div>\n<div id=\"sdfootnote12sym\"><a href=\"#sdfootnote12anc\">12<\/a> Some DBMSs use \u201cLEFT JOIN\u201d and omit the word \u201cOUTER.\u201d<\/div>\n<div id=\"sdfootnote13sym\"><a href=\"#sdfootnote13anc\">13<\/a> Some DBMSs use \u201cRIGHT JOIN\u201d and omit the word \u201cOUTER.\u201d<\/div>\n<div id=\"sdfootnote14sym\"><a href=\"#sdfootnote14anc\">14<\/a> Fiona Brown did not have an image for the full outer join. This image came from the W 3 schools website.<\/div>\n<div id=\"sdfootnote15sym\"><a href=\"#sdfootnote15anc\">15<\/a> Some DBMS use \u201cFULL JOIN\u201d and omit the word \u201cOUTER.\u201d<\/div>\n<div id=\"sdfootnote16sym\"><a href=\"#sdfootnote16anc\">16<\/a> The arrangement of the result set follows what Bhanu Priya used in her article. See https:\/\/www.tutorialspoint.com\/explain-division-operation-in-relational-algebra-dbms<\/div>\n<div id=\"sdfootnote17sym\"><a href=\"#sdfootnote17anc\">17<\/a> See Andrew Bone. \u201cHow the Division Operator Works in SQL,\u201d LearnSQL, June 4, 2021. https:\/\/learnsql.com\/blog\/sql-division-operator\/<\/div>\n<div id=\"sdfootnote18sym\"><a href=\"#sdfootnote18anc\">18<\/a> See https:\/\/mathworld.wolfram.com\/Calculus.html for more information.<\/div>\n<div id=\"sdfootnote19sym\"><a href=\"#sdfootnote19anc\">19<\/a> Unicode U+2227<\/div>\n<div id=\"sdfootnote20sym\"><a href=\"#sdfootnote20anc\">20<\/a> Unicode U+2203<\/div>\n<div id=\"sdfootnote21sym\"><a href=\"#sdfootnote21anc\">21<\/a> Unicode U+2200<\/div>\n<div id=\"sdfootnote22sym\"><a href=\"#sdfootnote22anc\">22<\/a> Douglas College has two campuses.<\/div>\n<div id=\"sdfootnote23sym\"><a href=\"#sdfootnote23anc\">23<\/a> Augustus De Morgan was a contemporary of Boole. De Morgan came up with two rules of logic that had been known informally.<\/div>\n<\/div>\n","protected":false},"author":2276,"menu_order":10,"template":"","meta":{"pb_show_title":"on","pb_short_title":"","pb_subtitle":"","pb_authors":["fredstrickland"],"pb_section_license":""},"chapter-type":[],"contributor":[66],"license":[],"class_list":["post-1180","chapter","type-chapter","status-publish","hentry","contributor-fredstrickland"],"part":3,"_links":{"self":[{"href":"https:\/\/pressbooks.bccampus.ca\/nelson\/wp-json\/pressbooks\/v2\/chapters\/1180","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pressbooks.bccampus.ca\/nelson\/wp-json\/pressbooks\/v2\/chapters"}],"about":[{"href":"https:\/\/pressbooks.bccampus.ca\/nelson\/wp-json\/wp\/v2\/types\/chapter"}],"author":[{"embeddable":true,"href":"https:\/\/pressbooks.bccampus.ca\/nelson\/wp-json\/wp\/v2\/users\/2276"}],"version-history":[{"count":3,"href":"https:\/\/pressbooks.bccampus.ca\/nelson\/wp-json\/pressbooks\/v2\/chapters\/1180\/revisions"}],"predecessor-version":[{"id":1183,"href":"https:\/\/pressbooks.bccampus.ca\/nelson\/wp-json\/pressbooks\/v2\/chapters\/1180\/revisions\/1183"}],"part":[{"href":"https:\/\/pressbooks.bccampus.ca\/nelson\/wp-json\/pressbooks\/v2\/parts\/3"}],"metadata":[{"href":"https:\/\/pressbooks.bccampus.ca\/nelson\/wp-json\/pressbooks\/v2\/chapters\/1180\/metadata\/"}],"wp:attachment":[{"href":"https:\/\/pressbooks.bccampus.ca\/nelson\/wp-json\/wp\/v2\/media?parent=1180"}],"wp:term":[{"taxonomy":"chapter-type","embeddable":true,"href":"https:\/\/pressbooks.bccampus.ca\/nelson\/wp-json\/pressbooks\/v2\/chapter-type?post=1180"},{"taxonomy":"contributor","embeddable":true,"href":"https:\/\/pressbooks.bccampus.ca\/nelson\/wp-json\/wp\/v2\/contributor?post=1180"},{"taxonomy":"license","embeddable":true,"href":"https:\/\/pressbooks.bccampus.ca\/nelson\/wp-json\/wp\/v2\/license?post=1180"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}