Questions tagged [relational-algebra]

Relational Algebra is an offshoot of first-order logic and of the algebra of sets that deals with relations (sets of tuples). In Computer Science, Relational Algebra is commonly used when dealing with databases. Operators in Relational Algebra use relations as operands and produce a relation as a result.

Relational Algebra provides a formal system for working with relations. In the context of databases, it can be thought of as a more formal way of constructing queries on relations.

Relational Algebra supports the following operations:

  • Set operators: Union (∪), Difference (-), Intersection (∩) (relations must be union compatible i.e., the number of attributes and their domains must match).
  • Projection (π): This is a unary operation that lets you select a specific subset of attributes (columns) from a relation.
  • Selection (σ): This is a unary operation such that the expression σφ(R) lets you select a subset of relations from the relation R that satisfy a certain propsition φ. This proposition is expressed using logical operators where the atoms are of the form aθb where a and b refer to attributes and θ refers to a binary operation in the set {<, <=, =, >=, >}
  • Rename (ρ): This is a unary operation of the form ρa / b(R) where the result is identical to R except that the attribute a has been renamed to b. This operator can be used to rename attributes or the relation itself.
  • Natural join (⋈): Natural joins (⋈) is a binary operator that is written as (R⋈S) where R and S are relations. The result of the operation is the set of all combinations of tuples in R and S that have equal values on their common attribute names.
  • Theta Join (⋈aθb): A theta join is a conditional join where the result of the operation is the set of all combinations of tuples in R and S that satisfy the condition specified. Using the already-defined operators a theta join can be expressed as R⋈φS = σφ(R × S).
  • Division (÷): Division is a binary operation that is written as R ÷ S. Assuming R is defined as R(a, b) and S is defined as S(b), the result of R ÷ S is the relation T(a) where a tuple <a> is only in T if there are tuples in R of the form <a, b> such that an a in R is associated with every value of b in S.

When teaching databases, Relational Algebra is used as a formal foundation before the introduction of SQL (Structured Query Language). SQL is similar to Relational Algebra except that it supports a few extended operators. A few of the differences can be summed up as follows:

  • Relational Algebra is procedural whereas SQL is declarative
  • Relational Algebra deals with sets of tuples whereas SQL deals with bags.
  • Standard Relational Algebra does not support aggregate operators like summing.
  • Standard Relational Algebra does not support grouping.
  • Standard Relational Algebra does not support ordering or sorting.
  • Standard Relational Algebra does not support pattern-matching operators.

External links:

577 questions
-2
votes
1 answer

How to convert Mysql query to relational algebra?

How to write mysql query SELECT book, COUNT(book) FROM booking GROUP BY book; in relational algebra? I thought Gcount(book)(booking) but doesn't seem right. I am following standards of Database Management Systems by Arun K Majumdar and Pritimoy…
user6849630
  • 1
  • 1
  • 2
-2
votes
2 answers

Relational algebra expression for queries

How do I make these expressions of relational algebra? These are the tables contained inside a bus driver database. • driver( driver_id, driver_name, age, rating); • bus( bus_id, bus_name, color); • reserves( driver_id, bus_id, date); Find the…
-2
votes
1 answer

Relational Algebra Homework (Arrays/Collection?)

My homework is called "relational algebra", and its asking me to perform the operations Union, Difference, Intersection, Join, Cartesian Product and Project on two tables in .txt files that read: a 1 a 1 b 2 and z 26 c 3 …
JMMM
  • 1
  • 1
-2
votes
3 answers

relational algebra and sql

Find the name and numbers of those candidates who have achieved one or more final grade between 11 and…
-2
votes
1 answer

How to count tuples containing the same value?

Suppose these are the columns: **name** **course** andy bio brian math andy chem How can I count the name "andy" appeared twice?
Umut
  • 409
  • 3
  • 7
  • 20
-2
votes
2 answers

finding max value among two table without using max function in relational algebra

Suppose I have two tables A{int m} and B{int m} and I have to find maximum m among two tables using relational algebra but I cannot use max function.How can I do it?I think using join we can do it but i am not sure if my guess is correct or…
user2916886
  • 847
  • 2
  • 16
  • 35
-2
votes
2 answers

Relational algebra operations

I'm stuck with relational algebra. I mean, how can I express functions like "SUM(), COUNT()," etc in RA? Thanks, any help will be kindly appreciated
-2
votes
2 answers

Writing the following query using relational algebra

I am trying to write the following query using the relational algebra: "Find the names of sailors who reserved a red or a green boat" Here is my solution: But the book gives the following solution: And another equivalent solution given by…
yrazlik
  • 10,411
  • 33
  • 99
  • 165
-2
votes
1 answer

Translate from SQL to relational algebra

Hey I have been asked this question: Translate the following SQL into relational algebra SELECT DISTINCT Student.Name, Course.Name FROM Student, Attendee, Course WHERE Student.Name = Attendee.Name AND Attendee.CourseId =…
-3
votes
1 answer

SQL and Relational Algebra queries for three tables: student, studies and course

I have a following tables, where primary keys are bolded. student (SID, SName, semester) studies (SID, CID) course (CID, CName, CCode) Write the SQL queries and Relational Algebra for the following statements. Find the names of all students in…
P_99
  • 9
  • 5
-3
votes
1 answer

relational algebra for this SQL for rows with values that appear more than 3 times

What is relational algebra for this SQL for rows with values that appear more than 3 times? select e.id, e.name, e.dno, COUNT(w.id) AS TOTAL_PROJECTS from employee e, works_on w where e.id = w.id group by e.id HAVING TOTAL_PROJECTS >…
-3
votes
1 answer

Relational Algebra - how does natural join work?

A natural join is an inner join that only works if table1 has some intersecting attributes with table2. Yet, when I take tables that have no column names in common, it acts as a Cartesian product. In addition, when I take different tables that have…
-3
votes
1 answer

Relational Algebra count something as rename

How can I count the number of somethings in each column, and rename as something? For example - this is my table: PATIENT PatientNum City --------------------------- 1 New York City 2 Boston 3 Birmingham 4 …
-3
votes
1 answer

How to use rename operator in SQL for relational algebra?

For example. Consider the relations college(cname, age, height) college2(name, age, height) How would I use natural join on this such that cname = name?
eem eeet
  • 3
  • 1
-3
votes
2 answers

Must a natural join be on a shared primary key?

Suppose I perform A natural join B, where: A's schema is: (aID), where (aID) is a primary key. B's schema is: (aID,bID), where (aID, bID) is a composite primary key. Would performing the natural join work in this case? Or is it necessary for A…
1 2 3
38
39