4C4 22 SQL LAB Assignment
4C4 22 SQL LAB Assignment
Practical .5
Objective:- To Implement rename operation and tuple variable.
Syntax: old-name as new-name
Query: Find the customer names, loan numbers, and loan amounts for all loans at the “XYZ”
branch. {Note: we want the attribute name loan-number to be replaced with the name loan-id}
Query: Find the names of all branches that have assets greater than at least one branch located in
“Jaipur”.
Practical .6
Query: Find the names of all customers whose street address includes the substring ‘path’.
Query: Find the names of all customers whose name starts with “A”.
Query: Find the names of all customers whose name ends with “k”.
Query: Find the names of all customers in which the second character is ‘a’.
Practical .7
ORDER BY Keyword
The ORDER BY keyword is used to sort the result-set in ascending or descending order. The
ORDER BY keyword sorts the records in ascending order by default. To sort the records in
descending order, use the DESC keyword.
ORDER BY Syntax
SELECT column1, column2, ...
FROM table_name
ORDER BY column1, column2, ... ASC|DESC;
ASC : Optional. ASC sorts the result set in ascending order by expression. This is the default
behavior, if no modifier is provider.
DESC: Optional. DESC sorts the result set in descending order by expression.
Query: List in alphabetic order all customers who have a loan at the “XYZ” branch.
Query: List the entire loan relation in descending order of amount and if several loans have
the same amount, order them in ascending order by loan number.
Practical .8
Intersect Syntax
SELECT column_name(s) FROM table1
INTERSECT
SELECT column_name(s) FROM table2;
Query: Find all customers having a loan, an account, or both at the bank.
Query: Find all customers who have both a loan and an account at the bank.
Query: Find all customers who have an account but no loan at the bank.
Practical .9
Set Comparision
(SQL allows < some, <= some, >= some, = some, and<> some comparisons,
< all, <= all, >= all, = all, and <> all comparisons
Query: Find the names of all branches that have assets greater than those of at
least one branch located in “XYZ”.
Query: Find the names of all branches that have an asset value greater than that of
each branch in "XYZ".
Query: Find the branch that has the highest average balance.
Query : Find all customers who have both an account and a loan at the
bank.
Practical .11
OUTER JOIN:
LEFT OUTER JOIN:
The LEFT OUTER JOIN keyword returns all records from the left table (table1), and the matched
records from the right table (table2). The result is NULL from the right side, if there is no match.