sqlrelational-algebra

SQL Relational Algebra Query


I have a schema that has two relations. One is loan which has the attributes loan-number, branch-name and amount. The other is borrower which has customer-name and loan-number as its attributes. These two relations are linked via loan-number.

How would I write a query in relational algebra to find the names of customers with a balance less than 10000?

How would I do this as a SQL query?


Solution

  • Do some research on relational algebra 8 main operators: restriction, projection, cartesian product, join, union, intersection, set difference and division.

    To answer your question:

    loan(loan_number, branch_name, amount)
    borrower(customer_name, loan_number)
    

    Perform a natural join of the both relations, apply the restriction (balance less than 10000) and then display the names with the use of a projection. The following 2 relational algebra expressions below will both answer your questionrelational algebra code

    meaning of symbols

    Both expressions evaluate to the following SQL query:

    select customer_name
    from borrower b, loan l
    where b.loan_number=l.loan_number and amount>10000;