1 / 42

Relational Algebra, Join and QBE

Relational Algebra, Join and QBE. Yong Choi School of Business CSUB, Bakersfield. Study Objectives. Learn about relational database algebra Understand Query-by-Example (QBE) Use Criteria in QBE Create Calculated Columns in QBE Calculate Statistics in QBE. Relational Algebra.

Download Presentation

Relational Algebra, Join and QBE

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Relational Algebra, Join and QBE Yong Choi School of Business CSUB, Bakersfield

  2. Study Objectives • Learn about relational database algebra • Understand Query-by-Example (QBE) • Use Criteria in QBE • Create Calculated Columns in QBE • Calculate Statistics in QBE

  3. Relational Algebra • Relational algebra is a procedural query language. • Relational algebra consists of a set of operations that take one or two relations as input and produce a new relation as their result. • Relational algebra is a high level query language because operations are applied to entire relations. • When specifying a relational algebra query, users must specifies how – in what order – to execute the query operations. • Difficult and no standard method.

  4. Relational Algebra (con’t) • Most commercial relational DBMSs provide a high-level declarative language interface. • So, the user only specifies what the result is… • Leaving the actual optimization and decisions on how to execute the query to the DBMS.

  5. Relational Algebra Operators • The relational algebra consists of a collection of high-level operators that operate on relations. • Each such operator takes either one or two relations as its input and produces a new relation as its output. • The traditional set operations: union, intersection, difference, and (Cartesian) product. • The special relational operations: select, project, join, and divide.

  6. Set Theory • The notation S  T will mean that S is a subset of T. • - e.g., {1, 2, 3}  {1,2,3,4} • If S is a subset of T and T contains at least one element that is not in S, then S is a proper subset of T. Notation for a proper subset is . • - e.g., {1, 2, 3}  {1,2,3,4}, {1, 2, 3}  {1,2,3,4} are true. • As far as a set is concerned, changing the order of elements does not change the set: e.g., {1, 2, 3} = {3, 2,1} • Two set A and B are disjoint iff A  B = .

  7. Union (R1 U R2) • Produces a relation that includes all the rows (tuples) in R1 or R2 or both R1 and R2 must be union-compatible (derived from the math). • Union-compatible: • Tables must have the same attributes characteristics to be used in the union. That is, columns and domains must have be identical such as name and format of the filed.

  8. Union Combines all rows

  9. Intersection (R1  R2) • Produces a relation that includes only the tuples that appears in both R1 and R2; R1 and R2 must be union compatible.

  10. Difference (R1 - R2 ) • Produces a relation that includes all the tuples in R1 that are not in R2; R1 and R2 must be union compatible. • How about R1 – R2?

  11. Product (R1 X R2) • Produces a relation that has the attributes of R1 and R2 and includes as tuples all possible combinations of tuples from R1 and R2. • Build a relation from two specified relations consisting of all possible combinations of tuples, one from each of the two relations.

  12. Product

  13. Select (<selection condition> (R)) • Do not confused with one of the SQL commands “select” • Select all tuples that satisfy the selection condition from a relation R. • The restriction operator effectively yields a "horizontal" subset of a given relation -- that is, that subset of the tuples of the given relation for which a specified comparison is satisfied.

  14. Select Yields a subset of rows based on specified criterion

  15. Project (<attribute list> (R)) • Produce a new relation with only some of the attributes of R and remove duplicate tuples. • The projection operator yields a "vertical" subset of a given relation --That is, that subset obtained by selecting specified attributes and then eliminating duplicate tuples within the attributes selected.

  16. Project Yields all values for selected attributes

  17. Divide Requires user of single-column table and two-column table

  18. Join Information from two or more tables is combined

  19. Inner Join • the most common type of join. • There must be a matching value in a field common to both tables. • all employees working on each project who live in the same city as where the project is taking place: SELECT Username, ProjectName, Location FROM Employee INNER JOIN Project ON Employee.City = Project.Location;

  20. Equi Join • Equijoin means the join between tables where the values of two or more columns are equal. • When a join condition relates two tables by an operator other than equality, it is a non-equijoin. SELECT e.first_name, d.department_name FROM employees INNER JOIN departments d ON e.department_id = d.department_id

  21. Other Joins • Theta JOIN • EquiJOIN that compares specified columns of each table using operator other than equality one • Outer JOIN • Matched pairs are retained • Unmatched values in other tables left null • Right and left

  22. Query-by-Example (QBE) • Query • Questions represented in a way the DBMS can recognize and process • QBE • Visual approach to writing queries • Used in MS-Access

  23. Simple Queries

  24. Simple Queries (con’t.)

  25. Query that Includes All Fields

  26. Query with Simple Criteria

  27. Query Using AND Criteria

  28. Query Using OR Criteria

  29. Query Using Two Conditions on a Single Field

  30. Query Using Computed Field

  31. Query to Count Records

  32. Query to Calculate an Average

  33. Query to Sort Records

  34. Query to Sort on Multiple Keys

  35. Query to Sort on Multiple Keys (con’t.)

  36. Query to Join Tables

  37. Query to Join Tables (con’t.)

  38. Query to Restrict Records in a Join

  39. Update Query

  40. Delete Query

  41. Make-Table Query

  42. Make-Table Query (con’t.)

More Related