-2

In the table: Students(id,name,scholarship), where scholarship can be NULL, I want to express using relational algebra the following query (show the names of the students that have a scholarship):

SELECT name FROM Students WHERE scholarship IS NOT null;
Cezar Cobuz
  • 1,077
  • 1
  • 12
  • 34
  • What version of RA, and what does "express SQL using RA" mean--a query with the same result? with some kind of similar structure? Also next time please google your question. This is a faq. Eg [Expressing “is null” in Relational algebra](https://stackoverflow.com/a/43430524/3404097). – philipxy Feb 13 '18 at 08:45
  • @philipxy I did research before adding my question, and in your example there is no accepted answer (as in other posts) that's why I posted the question in the first place. What do you mean by what version of RA are there many different versions of [RA](https://en.wikipedia.org/wiki/Relational_algebra)? – Cezar Cobuz Feb 13 '18 at 08:54
  • Yes there are many versions of RA. And google your title without quotes for lots of upvoted hits just from that one phrasing. See my linked answer's linked answer for more re dropping nulls. No upvotes prevents linking as a duplicate, but it's not a reason for posting a duplicate. PS Since there are no nulls in RA you need to tell us what it means when your SQL query has nulls in it before a translation can be done. Typically answers give a certain translation but that's just assuming a typical use of nulls. But we don't know how *you* use them if you don't say. – philipxy Feb 13 '18 at 09:10

1 Answers1

2

The relational model and algebra is based on binary logic (true/false), not 3-valued logic (true/false/null).

Decompose your Students relation into something like Students (id, name) and Scholarship (student_id, scholarship). The latter relation would only contain tuples for students who do have a value for scholarship.

An equijoin between the two relations will then allow you to get the names of the students who have scholarship.

reaanb
  • 9,806
  • 2
  • 23
  • 37