Questions tagged [relational-algebra]

For questions about the algebra of relational model theory, involving operations like Projection (π) Selection (σ), Rename (ρ), and Natural join (⋈).

42 questions
Filter by
Sorted by
Tagged with
47 views

FInd minimum and maximum number of tuples in R U πA,B ( R⋈S )

Given two relations R(A,B) with r tuples, S(B,C) with s tuples (r>0, s>0), find the min and max number of tuples in this relation: R U πA,B ( R⋈S ) Given options are: -min:r, max:r+s -min:0, ...
417 views

How to count in relational algebra without aggregate functions?

Find the user who has liked the most posts. Report the user’s id, name and email, and the id of the posts they have liked. If there is a tie, report them all. The schema: User(uid, name, website, ...
28 views

How can I calculate the cost of the query, if there is a `between` condition?

How can I calculate the cost of the query, if there is a between condition? Select * From A Where A.id between 10 and 50 If Index not exists and there is only one condition: Search in B+ tree to ...
397 views

Bag union operation in relational algebra

I have difficulty in understanding how does the bag union operates in relational algebra? Here, 1) has a schema (X, Y, A) 2) (Y, A) 3) (X, A) 4) (Y, A) so how will output look like after union ...
54 views

Delete duplicate keys with relation algebra without count

Hi I am new to relational algebra. I was wondering if there is a way to remove the tuples from a table using relational algebra that have the same Value occurring in multiple columns or same column ...
346 views

Delete duplicate keys with relation algebra

Hi I am new to databases and relational algebra. I was wondering if there is a way to remove the tuples from a table using relational algebra that have the same keys but different value. e.g. I want ...
29 views

Using relational algebra to check a condition for all

I encountered this question while revising for my finals exam on database theory. The following database contains information about car repair workshops. The following tables are used: Given two ...
101 views

Show the result of a set difference between tables Q and R [closed]

Assuming that we have two tables: Table Q D E a 1 b 2 g 1 Table R D E f 1 b 2 h 3 Show the result of a set difference between tables Q and R. My answer is D E a 1 g 1 But my classmates said the ...
111 views

Relational Algebra: how to express the combination of aggregation and projection?

Here I have a table, I would like to query the average salary of departments, the SQL statement should be select dept_name, avg(salary) from employee I try to express this SQL in relational algebra....
68 views

Long Relational Algebraic expression provided than actually required

Schema Diagram: Make a list of project numbers for projects that involve an employee whose last name is ‘Smith’, either as a worker or as a manager of the department that controls the project. The ...
435 views

Declarative and Procedural Query Languages

In the book Database System Concepts 6th Edition, Chapter 2 (Relational Algebra), it states that there are three formal query languages, the relational algebra, the tuple relational calculus and the ...
661 views

How to write group by and having in a relational algebra interpreter?

I am practising writing relational algebra (RA) expressions in RA interpreter from Duke, but I can't figure out how to represent group by or having (from SQL). I have this expression, but I need to ...
87 views

Equi Join On Union- and Intersection-Compatible Relations

Suppose that I have two union- and intersection-compatible relations; i.e., R1(A,B) and R2(C,D) as: Now , I want to find the join of both relations with equality conditions A=C and B=D. I have ...
27 views

Finding Exclusive Pairings in Relational Algebra

classId | studentId 0 0 0 1 0 2 1 0 1 1 1 2 2 2 How do you find the pairs of students (s1, s2) that ONLY have classes with ...
15 views

Relation Algebra: Selection of Cartesian Product

I am learning Relational Algebra basics for sql. I came across an example where the selection of cartesian product of two relations (R1 x R2) has been taken and I realize that it is same as selection(...
190 views

How to reuse a relational algebra expression without using assignment operator?

Can I write the following expression (σθ(R1)) × (σθ(R1)) as (ρR2(σθ(R1))) × R2 ? The first expression is not efficient since I am doing the same operation twice. So, basically, I am looking for ...
204 views

Nontrivial joining a relation with itself [closed]

I am a philosopher and am doing my first steps in relational algebra. So here is a puzzle: Let say that we have a relation R with attributes 'R.a' and 'R.b'. Is it possible to make a renaming and ...
49 views

Question concerning minimal/cannonical cover

For the question above, I am confused with how to approach simplifying the left hand side of BDCE->A. Do I get rid of E, as D depends on it, or do I get rid of CD as well, as CD->A? Here's what I ...
57 views

Converting from domain calculus to relational algebra

I have an assigned task at the uni and I have the three relations that follow: Customer (Name, City, Account) Offer (Product_Description, Supplier, Price) Order (Name, Product_Description, Quantity,...
4k views

How to represent NULL in relational algebra?

In the 3rd part of the question below: Study the tables given below and write relational algebra expressions for the queries that follow. STUDENT(+ROLLNO, NAME, AGE, GENDER, ADDRESS, ADVISOR) ...
594 views

I'm following a course in databases (Standford introduction to databases on YT) and, at some point, it's mentioned that t1 INNER JOIN t2 USING attr1, attr2 is equivalent to the NATURAL JOIN symbolized ...
81 views

Translating the Relational Algebra output

I have the following relation Jobs(name, company, salary). P1(salary) = πsalary(σcompany='pwc'(Jobs)) P2(salary) = πsalary(ρT1(s)(P1) thetaJoin(s>salary) P1) P3(salary) = P1 − P2 I know that P1 ...
111 views

Basic Relational Algebra Equivalence

The following relation schema: R(A,C), S(A,D), T(X,Y). Primary key attributes bold Would like to know why the following two are not equivalent queries Q1 = πA(σC<10(R)) and Q2 = σC<10(πA(R)) ...
2k views

Can a Join happen with same attribute names, but different domains?

Problem When doing any sort of Join all common attributes are listed under one column in one way or another. However, I have not been able to find a source that deal with columns of the same name, ...
332 views

Difference of sets with different amount of columns?

Problem When there exists two sets, R and S, and we take the difference R - S, we remove the elements from R that exist in S. For cases where the number of columns are the same on both sides, such ...
6k views

Is there a shortcut for 'SELECT * FROM table' in relational algebra?

Problem A question I once found on a test was worded as such: Report the book information for the book with ISBN=43221 The relational schema for a book is depicted below: πISBN, title, type, ...
110 views

Do my relational algebra operations produce the desired results?

I have these tables: Sailors sid sname rating age --- ------ ------ --- 22 dustin 7 45 31 john 8 55 58 ben 10 35 Boats ...
7k views

How are joins Commutative and Associative?

I have read all over the place that joins are associative and commutative. So A join (B join C) should be the same as (A join C) join B. But I have a really hard time understanding how this can be ...
2k views

Why does the UNION operation require that the relations on which they are applied be union compatible?

With respect to the operations in relational algebra (not in SQL): I'm having trouble understanding why 2 relations have to be union-compatible before the union operation can be applied on them. I ...
207 views

the verbosity of "(SELECT * FROM A)"?

This might be a novice question. But sometimes, I find it necessary to use things like (SELECT * FROM A) in doing relational algebra in SQL (instead of using the relation A itself). For example, ...
9k views

Converting SQL to Relational Algebra / Calculus

I have designed a schema and generated a few SQL queries. I'm using PostgreSQL. For example: CREATE TABLE train ( train_code SERIAL PRIMARY KEY, name TEXT NOT NULL ); CREATE TABLE journey ( ...
5k views

Find the highest graded student in each state, using Relational Algebra

Suppose I have a table of students, containing their ID, grade and state: ------------------------- | id | grade | state | ------------------------ | 1 | 83 | CA | | 2 | 94 | TX ...
28 views

Do Selection attributes have to appear in Projection list in Relational Algebra

In extended relational algebra (aggregation being allowed) do you have to project all attributes that you use in a statement? So for example in the query below the attributes A.FO_ID and A.Arrival are ...
6k views

Counting distinct entries in a column using relational algebra

So I have a table similar to this one. Each user has posted a review about one or more hotels(A,B,C,D) but on different dates so there are no duplicate tuples even though a person might have reviewed ...
145 views

Relational Algebra Equivalence (basic)

I'm just getting started on an intro to databases course and have a question about writing relational algebra expressions. Schema: Person ( name, age, gender ) Frequents ( name, pizzeria ) Eats ( ...
2k views

Proof that Inner Join is Commutative

I'm trying to prove to myself that the order of inner joins doesn't matter, but, in an abstract sense, I'm coming up with nothing. How would one go about proving that the order of a set of INNER ...
28k views

Minimum and Maximum Number of Tuples

Consider Relations R and S where are R is having m tuples and S is having n tuples . m<=n . What would be the minimum and maximum number of tuples in each of the following cases (Assume that ...
567 views

Is it posible to join relation without primary key attribute?

I have go through this but I couldn't understand. Can I join reation without primary key or partial key? If yes what is the answer for following question.
2k views

Creating relationships between tables that where not specified in the given UML diagram

Good evening! I'm working on designing my very first actual database from the following UML class diagram (in French unfortunately): I'm at the point of creating the relational sketch of it which I ...
1k views

Convert query in words to relational algebra

I have a follow-up question to a question I have previously asked on SO. Instead of the query from my initial question, I want to convert the following into relational algebra: List the names and ...