# Questions tagged [relational-algebra]

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

43 questions
Filter by
Sorted by
Tagged with
0answers
115 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, ...
0answers
19 views

### Find every hashtag that has been mentioned in at least three post captions on every day of 2017 (relational algebra)

I have this schema: (this is just part of it, I don't think the rest is necessary for this) Post(pid, uid, when, location, caption) Hashtag(pid, tag) Hashtag[pid] contained in Post[pid] "when&...
0answers
21 views

### Relation algebra problem with renaming columns

I am trying to rename a 2 columns after joining them together ρ mmnr←MM.Kortnr, ebnr←EB.Kortnr π Passagerare.Namn, Passagerare.Personnr, MM.Kortnr, EB.Kortnr Passagerare ⟕ Passagerare.Personnr =EB....
1answer
18 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 ...
1answer
227 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 ...
0answers
39 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 ...
2answers
131 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 ...
0answers
26 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 ...
2answers
85 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 ...
0answers
71 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....
1answer
45 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 ...
1answer
311 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 ...
0answers
597 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 ...
0answers
81 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 ...
0answers
21 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 ...
0answers
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(...
2answers
177 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 ...
2answers
155 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 ...
1answer
45 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 ...
0answers
54 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,...
1answer
3k 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) ...
1answer
468 views

### Equivalent of SQL’s “INNER JOIN USING” in relational algebra

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 ...
2answers
74 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 ...
0answers
108 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)) ...
1answer
1k 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, ...
1answer
224 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 ...
2answers
5k 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, ...
1answer
102 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 ...
2answers
6k 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 ...
1answer
1k 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 ...
1answer
196 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, ...
1answer
7k 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 ( ...
2answers
4k 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 ...
0answers
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 ...
2answers
5k 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 ...
0answers
134 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 ( ...
1answer
1k 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 ...
2answers
20k 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 ...
1answer
393 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.
2answers
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 ...
1answer
915 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 ...
0answers
144 views

### How to express inclusive and exclusive relations in relational algebra and relational calculus?

Let be the following simplified database sketch: R1(P,S),R2(S,T) and R3(T,S) with P= people S = Sport and T= Sports Center How to find in relational algebra and relational calculus which couples ...
1answer
1k views

### Theta join explanation

Take the following relational schemes: R(A, B, C) S(D, E, F) where the attributes A and D are the primary keys, respectively. Assume to have an instance r of R with n tuples and an instance s of ...