580 questions
-4
votes
2
answers
111
views
Why should the operands for UNION be SELECT statements and not tables?
In SQL, given tables T and S that have the same schema, say,
CREATE TABLE "T" ("ID" INTEGER, "Salary" REAL);
CREATE TABLE "S" ("ID" INTEGER, "...
-1
votes
1
answer
57
views
Why do these sample relations have many valid joins but only one composition?
I am trying to understand some of the claims from a paper that introduced relational databases. Reference: https://www.seas.upenn.edu/~zives/03f/cis550/codd.pdf
The author claims that some example ...
-1
votes
1
answer
295
views
Can modern SQL syntax be translated into a relational algebra tree?
I have a parsed representation of an SQL query in the form of an abstract syntax tree.
I'd like to convert it into an intermediate logical tree representation, which can in turn be expanded into ...
-2
votes
1
answer
68
views
How do the attributes suddenly came into play since the exercise statement didn't specify these two at the start? [closed]
My exercise answer heavily relies on relational algebra procedural query language.
Consider the following relational database schema:
person(ID, firstName, lastName, nickName)
follows(pID1, pID2)
...
-1
votes
1
answer
476
views
"Exactly one" in Relational Algebra
Assume relational database schema
PEOPLE = {ID, Lastname, Firstname}
CAR = {PID, Color}
FK PID ⊆ PEOPLE{ID}
The relational algebra I used is from Fundamentals of Database Systems, 7th Edition (...
0
votes
0
answers
50
views
joining tables in relational algebra, what happens to the attributes which have the same name?
the database
I am trying to join the Employee and Customer tables, but what happens to the attributes which have the same name, because they are storing data that isn't the same?
Maybe both are kept ...
-3
votes
2
answers
206
views
Can Selections on Cartesian Products be re-written as Theta Joins.? [closed]
I have read it somewhere in article on query optimization that instead applying selections on cartesion product, it is better to use selection theta joins.
So basically if we have 2 employee tables ...
0
votes
0
answers
258
views
relational algebra expression and the sql query
Use the following query to compute a new table.
section_and_time =
π course_id, sec_id, semester, year, day, start_hr, start_min, end_hr, end_min
(section ⨝ time_slot)
Using only ...
-3
votes
1
answer
2k
views
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 ...
-1
votes
1
answer
899
views
How to get ORDER BY clause representation in Relational Algebra?
I want to get account related information by using Relational Algebra based on the descending order of the balance attribute.
Table:
Account (id, account_number, branch_name, balance)
How to get ORDER ...
0
votes
0
answers
214
views
Relational Algebra: Problems with division operator
I am writing a query, where I am using the division operator. For some reason I can't get it to work properly, and I can't see why.
pol = pi allergen (sigma allergy_type = 'pollen' (allergies))
tmp = ...
0
votes
0
answers
195
views
How to implement the division of two relations in mapreduce?
I want to implement the division of two relations in MapReduce. I have two relations: T(A,B,C) and U(B,C). I know that
for the relations R(A,B,D) and S(A,B). This is pretty much my scenario. I am not ...
0
votes
0
answers
299
views
Relational algebra: Difference between dates
Which function should I use to express the difference of dates. End and Start date differences must be more than 3 days.
σ EndDate - StartDate > 3 (Residence)
Error at line 1: function "sub&...
0
votes
0
answers
31
views
How can i display a different tuple in a Table that came from a merge by other tables?
This is about relational algebra,
I have a table and im always having the problem of not being able to project what I want, but I think im almost right. For example, in this case I need to find all ...
-1
votes
1
answer
337
views
Pair of atributes as a relation key - relational algebra [duplicate]
I'm trying to detect if the attribute pair (A, B) is the relation key for R(A, B, C).
Specifically, I want to write a query in relational algebra that will return an empty set if and only if (A, B) is ...
-1
votes
1
answer
679
views
Is there a way to refer to the current date in relational algebra, like CURDATE in MySQL?
I want to write a constraint using relational algebra that the current date has to be less than the expiry date in a specific relation. I'm aware this is easy in SQL, but not sure how to do it in ...
0
votes
1
answer
855
views
Finding max without aggregate operation in relational algebra
How can I find the maximum without using aggregate operation in relational algebra?
The schema of Database is as follows
Item(IName, Brand)
Shop(SName, City, Address)
Sells(IName, SName, Price)
How ...
-1
votes
1
answer
55
views
RA translation to natural language
so im stuck in this exercise where I need to translate relational algebra (unary relational operations) expressions based on the Mondial III database to natural language and I need help for the last ...
-2
votes
1
answer
530
views
convert SQL query containing keyword EXIST to relational algebra
select fname, lname, salary
from employee
where exists (
select essn from dependent where employee.sex = dependent.sex
);
How do I convert that SQL query containing keyword EXIST to ...
0
votes
0
answers
401
views
How to add virtual column in relational algebra
Suppose we have table A and a table B which has foreign key referencing A's PK.
The following query in SQL selects all rows and columns of A and an aggregation (for example SUM) of Bs for each row of ...
-1
votes
1
answer
213
views
How can a referential integrity constraint be expressed through relational algebra?
What does it mean to write an algebraic relational expression for a referential integrity constraint in a database design?
0
votes
1
answer
428
views
Does the term "row set" and "row" have different meaning in the SQL vocabulary?
Consider the relation enrolled(student, course) in which (student, course) is the primary key, and the relation paid(student, amount) where student is the primary key. Assume no null values and no ...
0
votes
2
answers
208
views
When a database table is vertically partitioned, what is the relationship between the partitioned table and the table before partitioning?
While studying database related content, I came across the following:
When table R is vertically partitioned into R1, R2, R3..., Rn, it is
said that it can be expressed as R = R1⋈R2⋈R3...⋈Rn. (⋈ is ...
0
votes
1
answer
3k
views
Select * in Relational Algebra
Please explain how to express this SQL statement in relational algebra
select * from Books
When I search I could find a lot of examples with where clause, I just need to verify that it is σ Books or ...
0
votes
1
answer
259
views
What is the difference between having the JOIN(⋈) inside the relation instance and before the other selection operator (like SELECTσ)?
I'm having trouble understanding how to provide proper relational algebra expressions to some of my assignment problems. I realized instead of having the JOIN selection operator outside the relation ...
0
votes
0
answers
947
views
How to select multiple attributes along with grouping operation in Relational Algebra Queries?
Say I have a table called T with attributes a1, a2, a3, a4, a5. Now I want to convert the below from SQL query to relational algebra query.
SELECT a1,a2,a3, COUNT(a4) AS counta4 FROM T GROUP BY a1;
...
-3
votes
1
answer
338
views
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
...
-2
votes
1
answer
2k
views
How to combine two columns in relational algebra?
I have a query of the form
select member.first_name||' '||member.last_name as member_name
from member
MINUS
select distinct member.first_name||' '||member.last_name as member_name
from member,...
-1
votes
2
answers
415
views
Relational Algebra to SQL involving Natural Join
A NATURAL JOIN should not have a condition.
How is this relational algebra translated to SQL?
σ SupplierId=’Datec’ (r(Asset) * r(Supplier))
0
votes
1
answer
252
views
Either or relational algebra enterprise constraint
I need to define a constraint where tuples in a booking table can only have a value in musician (foreign key attribute from musician table) or actor (foreign key attribute from actor table), and must ...
-1
votes
1
answer
296
views
How to compare two sets in MySQL or SQL SERVER?
In this University Database:
CREATE TABLE Stud(
[S#] INT PRIMARY KEY,
Sname NVARCHAR(50),
City NVARCHAR(50),
GPA FLOAT,
[Clg#] SMALLINT
);
CREATE TABLE Sec(
[Sec#] SMALLINT,
...
-1
votes
1
answer
224
views
Finding tuples if it only exists in all occurrences of a constraint
Database (all entries are integers):
ID | BUDGET
1 | 20
8 | 20
10 | 20
5 | 4
9 | 4
10 | 4
1 | 11
9 | 11
Suppose my constraint is having a budget of >= 10.
I would want to return ID of 1 only ...
0
votes
2
answers
1k
views
How do I replace EXISTS and NOT EXISTS with JOIN in SQL so I can translate it to relational algebra?
I want to replace EXISTS and NOT EXISTS in the following query:
SELECT pokemon_name FROM sinnohdex s
WHERE NOT EXISTS
(SELECT * FROM hoenndex h
WHERE s.id = h.id)
AND EXISTS
(SELECT * ...
0
votes
1
answer
568
views
Is cross or Cartesian product in relational algebra same as JOINS in SQL? [closed]
I am confused whether cross or Cartesian product in relational algebra same as JOINS in SQL. If not, What is the equivalent of cross-product in SQL?
2
votes
1
answer
398
views
Is this natural join operation used correctly? (Relational Algebra)
I have the following task given from the professor:R-E Modell
Assume the companies may be located in several cities. Find all companies located in every city in which “Small Bank Corporation” is
...
0
votes
1
answer
237
views
Simplify nested queries
select name
from person, author, article
where name != "John Doe" AND
person.pid = author.pid AND
author.aid = article.aid AND
title = select title
from ...
0
votes
1
answer
811
views
Query in relational algebra
I have 2 tables and I need to write a query in relational algebra that will select all names of teams, who are not working with any client.
I have these relations
team( id, name )
client( id, name, ...
0
votes
1
answer
2k
views
Relational Algebra Join - necessary to rename?
Let's assume i have some 2 simple tables:
IMPORTANT: This is about relational algebra, not SQL.
Band table:
band_name founded
Gambo 1975
John. 1342
Album table:
album_name band_name
...
-3
votes
1
answer
2k
views
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 ...
-1
votes
1
answer
154
views
Relational algebra - sql (common operators)
I have these relational schemes:
Participate (FestivalName, Artist)
Attend(ID, FestivalName)
Prefer (ID, FestivalName)
Like (ID, Artist)
I would like to list the people which only attend festivals ...
-1
votes
1
answer
429
views
Translating from Relational Algebra to SQL
the following exercise asks me to translate from relational algebra to SQL code.
I am still not very familiar with relational algebra, but I have tried to code the following relations in SQL, but I ...
0
votes
3
answers
833
views
Maximum number that can be returned by 2 Natural Joins
Given relations A(a,b,c), B(e,f), C(d,g,h), where A has 800 tuples, B 200 and c 500. In worst case gives the expression A * B * C ( with * natural join) :
a) 800 tuples
b) 200 tuples
c) 500 tuples
...
3
votes
2
answers
342
views
How to use a set algebra operation in SQL
I need to find the distinct drinkers who like either BEER or RED WINE. However, the query must be implemented with a set algebra operation.
Here is what I have so far:
SELECT DRINKER
FROM LIKES
...
-2
votes
2
answers
2k
views
Find the Cardinality of Natural Join
|X| represents number of tuples in X bold letters represent keys in the relation
Consider the relations R(A, B) and S(A, C), and that R has a foreign key on A that
references S. |R ✶ S| (where ' * ' ...
-1
votes
1
answer
198
views
Is a separate database table required if it's in a many-to-many relationship and only has a single column?
Say I have a system that catalogues books and I want to group them into genres and there is a UNF tuple:
BookId (PK): number
BookTitle: string
Blurb: string
Genres: string[]
(... everything else)
...
-3
votes
1
answer
835
views
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 ...
-2
votes
2
answers
587
views
SQL Relational Division query [closed]
I have three tables student(ID, name), takes(ID, course_id), course(course_id, dept_name).
I would like to query student ID and name who take all courses from dept_name = 'Comp. Sci.'.
I know I need ...
0
votes
2
answers
2k
views
Why can't I compare 2 tables with Different number of Tuples in Relational?
A Question came up in class and I am not sure I am understanding the answer. In the program relational https://ltworf.github.io/relational/ , when using the ∩ operator, you MUST have tables with the ...
0
votes
0
answers
629
views
How do I filter by date and count these dates using relational algebra (Reframe)?
I'm really stuck. I read the Reframe documentation https://reframe.readthedocs.io/en/latest/ that's based on pandas and I tried multiple things on my own but it still doesn't work. So I got a CSV file ...
1
vote
1
answer
302
views
Relational Algebra (sanity check): branches whose customers include all Tulsa customers
Given These Schemas:
Account: bname, acct_no, balance
Depositor: cname, acct_no
Customer: cname, street, city <-(all customers / both loan and account customers)
Loan: loan_no, ...