Questions tagged [relational-algebra]
For questions about the algebra of relational model theory, involving operations like Projection (π) Selection (σ), Rename (ρ), and Natural join (⋈).
44
questions
1
vote
1
answer
241
views
Why is it called "semi-join"?
If my understanding is correct, a semi-join is a way of selecting records from one dataset that have related (via a common attribute) records in another set. So where does the "semi" come ...
2
votes
1
answer
157
views
Unsure how to formulate Relational Algebra Query
The question asks:
Given two relations A and B, Both of which are over attributes x and y. Write a query under bag semantics that returns A if B is empty and B otherwise
The way I interpreted this ...
-2
votes
1
answer
55
views
Print all the row with two or more element in the column
In following table how to print the student number when age occur two or more times, The result should be only column Sno i.e.
Result
Sno
Reason
1
because 18 occur two times
2
because 20 occur ...
-1
votes
1
answer
59
views
Prove that R ⟕ S = R ⨝ S
Given the relations R(a, b, c) and S(b, d), where {R.a, R.b} is the primary key of R, {S.b} is the primary key of S, and {R.b} is the foreign key in R, which refers to {S.b} (the data is already give ...
0
votes
1
answer
292
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, ...
0
votes
0
answers
977
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, ...
1
vote
1
answer
113
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 ...
-1
votes
1
answer
1k
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 ...
0
votes
0
answers
244
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 ...
0
votes
2
answers
2k
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 ...
1
vote
0
answers
60
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 ...
1
vote
2
answers
164
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 ...
2
votes
0
answers
512
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....
3
votes
2
answers
187
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 ...
3
votes
1
answer
585
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 ...
2
votes
0
answers
972
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 ...
1
vote
0
answers
91
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 ...
1
vote
0
answers
25
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(...
-1
votes
2
answers
311
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 ...
-2
votes
2
answers
525
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 ...
1
vote
1
answer
94
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 ...
2
votes
0
answers
87
views
Converting from domain calculus to relational algebra
At university I have been given these three relations:
Customer (Name, City, Account)
Offer (Product_Description Supplier, Price)
Order (Name, Product_Description, Quantity, Supplier)
and this ...
0
votes
1
answer
6k
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)
...
1
vote
1
answer
792
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 ...
2
votes
2
answers
98
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 ...
0
votes
1
answer
3k
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, ...
1
vote
1
answer
928
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 ...
2
votes
2
answers
9k
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, ...
4
votes
1
answer
119
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
...
8
votes
2
answers
10k
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 ...
-1
votes
1
answer
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 ...
5
votes
1
answer
223
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, ...
2
votes
1
answer
10k
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
(
...
1
vote
2
answers
8k
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 ...
2
votes
0
answers
44
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 ...
1
vote
2
answers
8k
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 ...
1
vote
0
answers
166
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 ( ...
3
votes
1
answer
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 ...
3
votes
2
answers
39k
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 ...
-4
votes
1
answer
2k
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.
5
votes
2
answers
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 ...
10
votes
1
answer
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 ...
1
vote
0
answers
171
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 ...
5
votes
1
answer
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 ...