# 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)
COURSE(+COURSEID, CNAME, CREDITS)
PROFESSOR(+PROFID, PNAME, PHONE)
``````

Primary keys are preceded by a +. ADVISOR is a foreign key referring to PROFESSOR table. ROLLNO and COURSEID in ENROLLMENT are also foreign keys referring to THE primary keys with the same name.

1. Names of femal students
2. Names of male students along with advisor name
3. Roll Number and name of students who have not enrolled for any course.

How do I represent NULL marks in relational algebra?

I projected `STUDENT` `NAME` and `ROLLNO` after assigning `COURSEID` from `ENROLLMENT` table as

``````COURSEID = NULL
``````

Is this valid?

There are no NULL values in relational algebra. Here you can use the antijoin operator ▷:

πROLLNO, NAME(STUDENT ▷ENROLLMENT)

that selects all records from STUDENT where the ROLLNO is not in ENROLLMENT.

In SQL there are NULL values. You may use a left outer join and select the rows where the courseid is NULL:

``````select STUDENT.ROLLNO, STUDENT.NAME
from STUDENT left outer join ENROLLMENT
on(STUDENT.ROLLNO=ENROLLMENT.ROLLNO)
where ENROLLMENT.COURSEID is null
``````
• I would upvote if you didn't use nulls in the SQL code either. A `NOT EXISTS` subquery would be much nicer. Commented Jun 24, 2018 at 21:05
• @ypercubeᵀᴹ there are different methods to get the result in SQL. The NOT EXISTS is the SQL equivalent to the antijoin operation of relational algebra. But I didn't want to be nice but wanted to show why the OP is talking about NULLs. From the comments to the OP one could conclude that there is no reason that the OP thinks about NULLs. Commented Jun 24, 2018 at 23:15