Given the schema Students(id:integer,grade:integer)
, you can solve the problem in tuple relational calculus by using the negation operator (¬
).
{T1.id | ∃T1 ∈ Students ¬(∃T2 ∈ Students (T2.grade > T1.grade))}
This would return the id of all students in T1 where there is no student in T2 with a higher grade.
Because T1 and T2 are from the same relation, this effectively returns the set of students with the top grade.
If there are no ties for the top grade, it will return just one id.
It looks like you were thinking in terms of relational algebra rather than tuple relational calculus.
Tuple relational calculus does not have a set difference operator, so you can't find the maximum by subtracting all non-maximums.
Reference
The Solutions Manual for the third edition of Database Management Systems by Ragu Ramakrishnan and Johannes Gerke helped me solve this.
Question 4.3 asks you to solve some problems using this schema:
Suppliers(sid:integer,sname:string,address:string)
Parts(pid:integer,pname:string,color:string)
Catalog(sid:integer,pid:integer,cost:real)
Question 4.3.11 is similar to yours.
Find the pids of the most expensive parts supplied by suppliers named Yosemite Sham.
The solution looks like this:
{T | ∃T1 ∈ Catalog(∃X ∈ Suppliers
(X.sname = 'Yosemite Sham' ∧ X.sid = T1.sid) ∧ ¬(∃S ∈ Suppliers
(S.sname = 'Yosemite Sham' ∧ ∃Z ∈ Catalog
(Z.sid = S.sid ∧ Z.cost > T1.cost))) ∧ T.pid=T1.pid)}
The solution here is more complicated because of the joins between Suppliers and Catalog, but the essence of the solution is the same.
Elide the joins to get this:
T1 ∈ Catalog ...
(... ¬(... ∃Z ∈ Catalog
(... Z.cost > T1.cost)))
In the reference solution, free variable T has the same pid as bound variable T1.
Taking the pid of T1 directly is a simpler way to get the same result.
I agree with @Erik, these instruments are essentially equivalent, but I am going to add a few more ideas about this topic.
Context
In order to provide more context, it is necessary to have an authoritative definition for both terms. So, here are some excerpts from the relevant paper entitled Relational Completeness of Data Base Sublanguages, which was writen by the originator of the relational model, Dr. E. F. Codd, and published in 1972:
Relational algebra. The primary purpose of this algebra is to provide a collection of operations on relations of all degrees (not necessarily binary) suitable for selecting data from a relational data base.
Relational calculus. Having defined a relational algebra, we now consider an applied predicate calculus which may also be used in the formulation of queries on any data base consisting of a finite collection of relations in simple normal form.
In this way, one can see that they serve the same purpose, since they are two different mathematical means to express a group of operations considered valid within the relational framework.
Comparison of both approaches
In the same paper, Codd contrasts both methods in order to point out some important aspects in which each one stands out:
One advantage that might be claimed for the algebraic approach is its freedom from quantifiers. Howerver, the calculus appears to be superior to algebra in four respects.
- Ease of augmentation
- Scope for search optimization
- Authorization capability
- Closeness to Natural Language
So, these aspects should be taken into account by organizations that aim to build their own languages or database platforms.
Practical value
I do not know if there are contemporary successfully commercial RDBMS that provide query languages purely based on relational calculus, but I deem that its practical worth lies in the fact that it offers a theoretically grounded alternative for vendors who plan to design and implement a new valid relational language, or extend an existing one without departing from proven and accepted practices. In this respect, it can be useful to think of relational calculus as a blueprint that such vendors can follow in order to produce a relational language.
Since the market is largely dominated by SQL platforms, millions of users around the world are already familiar with several of its particular dialects, and billions of dollars are invested in such platforms, it would be very interesting to determine whether creating new relational lenguages would be profitable, but if so, relational calculus could always play an important role.
Of course, such projects can be much more feasible in the academic field, so there is more practical value regarding this tool.
Best Answer
As Martin said, this means "not equals"