DB Ass 3 Solved
DB Ass 3 Solved
Assignment: 3
Instructor: Abdul Rehman
Submitted by Mubashra Qadir
MITE-F20-007
26/07/2021
Q32. Write a SQL query to get the third highest salary of an employee from
employee_table?
Ans: Dense_rank function: Here we will use the dense_rank function, that computes the
rank of a row and returned the rank as number. This function accepts arguments in data type
only. In case of tie, it gives equal rank to all rows.
Select * from (select ename, sal, dense_rank()
Over (order by sal desc) r from Employee_table)
where r = &3;
Q35. How can you insert NULL values in a column while inserting the data?
Ans: You can insert NULL value into a column if the column must not have NOT NULL
constraints. Or whenever you do not pass any value for column compiler inserts null value by
default.
Q36. What is the main difference between ‘BETWEEN’ and ‘IN’ condition operators?
Ans: Both of these operators are used to find out the multiple values from the table.
BETWEEN operator is used to select a The IN operator allows you to specify
range of data between two values. multiple values.
Syntax: Syntax:
SELECT * FROM tbl_result SELECT * FROM tbl_result
WHERE marks BETWEEN 50 AND 80 WHERE marks IN (90, 95)
Q44. How can you fetch common records from two tables?
Ans: You can use Intersect Key word, which gives you common records.
Syntax:
Suppose we have two tables student and student1, we will write the following query to find
the common records from the two tables:
(Select * from student) Intersect (Select * from student1)
Q45. List some case manipulation functions in SQL?
Ans: Some of case manipulation functions are:
1. LOWER
The lower function is used to convert a given String into lower case.
2. UPPER:
Upper Function converts given character String to Upper Case.
3. INITCAP
INITCAP Function converts every first letter of the word to uppercase and rest of them to
lower case in a given String.