SQL FROM clause

SQL FROM clause

SQL FROM clause by itself defines a Cartesian product of the relations in the clause. Since the natural joint defined in the terms of a Cartesian product a SELECTION, and a PROJECTION, it is relatively simple matter to write SQL expression for the natural join.
“For all customers who have a loan from the bank find their names and loan numbers”
Select distinct cust-name, borrowers.loan-no
From  borrowers.loan_no
Where borrowers.loan_no = loan.loan_no

Using SQL FROM clause

It is important to note here, that SQL also use table-name.column-name convention (similar to relational algebra concept), if the same column name appears in more than one table in the FROM clause. As the attribute cust_name appears only one of the tables named in the from clause, there is no ambiguity when we write cust_name. To write more complicated queries in SQL we can use logical connectives such as AND, OR, NOT. Consider a case we have more than one constraint to be specified in where clause to find all customers and loan numbers who have a loan in KR CIRCLE, BRANCH we write the query as:

select distinct cust-name, borrowers.loan-no
From  borrowers,loan_no
Where borrowers.loan_no = loan.loan_no  AND branch_name = “KR CIRCLE

Leave a Reply

Your email address will not be published.