SQL Interview Questions and Answers
SQL Interview Questions and Answers
crack the SQL Interview and what could be the probable 2020 SQL Interview
Questions. Every interview is different and the scope of a job is different too.
Questions and Answers for 2020 to help you get success in your interview.
Below is the list of 2020 SQL Interview Questions and Answers, which can be
asked during an interview for fresher and experience. These top interview
1. What is SQL?
Answer:
For example
This is the basic SQL interview questions asked in a SQL interview. There are
multiple ways to solve this question, below three are the easiest solution for it.
1st: Select max (salary) from employee where salary not in (select max(salary)
from employee).
Note: This solution is only to find the 2nd highest salary, if the question got
the change to find the 3rd or 4th highest salary then this will not work. You
need to execute the below query for finding nth highest salary.
2nd: Select Salary from employee where salary in (select salary from employee
where level = &topnth connect by prior Salary > Salary group by level).
Note: If you run the above query it will ask for entering the value of topnth, if
you enter 2 it will show the result for 2 and if you enter 3 it will give the result
3rd: Select salary from employee where salary in (select salary from (select
unique salary from employee order by salary desc) group by rownum, salary
There are multiple ways to solve this question, below two are the easiest
1st: Select min (salary) from employee where salary not in (select min(salary)
from employee).
Note: This solution is only to find the 2nd lowest salary, if the question got the
change to find the 3rd or 4th lowest salary then this will not work. You need to
execute the below query for finding nth highest salary.
2nd: Select Salary from employee where salary in (select salary from employee
where level = &lownth connect by prior Salary < Salary group by level).
Note: If you run the above query it will ask for entering the value of lownth, if
you entering 2 it will show the result for 2 and if you enter 3 it will give the
NVL: Syntax
Note: If EXPR1 is character data then EXPR2 may any data type.
Output: 100
Select NVL(null,200) from dual;
Output: 200
NVL2: Syntax
NVL2(expr1,expr2,expr3)
If expr1 is not null, NVL2 returns expr2. If expr1 is null then, NVL2 returns
expr3.
The data type of the return value is always the same as the data type of expr2
Output: 200
Output: 300
Anubhav [email protected]
Basant [email protected]
Sumit [email protected]
Amit [email protected]
distinct domain).
Answer:
Part 2 – SQL Interview Questions (Advanced)
Let us now have a look at the advanced Interview Questions.
Anubhav 26 50000
Anurag 29 60000
Basant 27 40000
Rahul 28 45000
Anubhav 27 48000
Answer:
from Employee where name in (Select name from employee group by age,
Or
Delete from employee where rowid not in (select max (rowid) from employee
group by name);
9. Write the Query to find odd and even records from the table?
Answer:
Select * from employee where empno in (select empno from employee group
by empno, rownum having mod(rownum,2) = 0);
Select * from employee where empno in (select empno from employee group
create a new table with data and structure copied from another table
Create an empty table with the same structure as some other table
Or
Intersect
Minus