Home » SQL

Category Archives: SQL

SQL Interview Questions

Every Java developer can expect few Sql interview questions during Java Interview.Though the level of difficulty and depth of questions are not easier compared to a PLSQL developer,still he/she is expected to answer questions correctly.Below are some of the questions ,you can see and go for interview.
1. What is the difference between unique key and Primary Key ?

Answer : Both Unique Key(UK) and Primary key(PK) can be a column or group of columns(composite) which can be used as an identification of uniqueness of a row in a table. Unique key allows null ,nut primary key does not allow null.In a table only one primary key is possible ,but the same table can have multiple unique keys.Primary key creates clustered index(logical order of the index same as  physical stored order of rows ) ,but unique  key creates non clustered index(logical order of the index different from  physical stored order of rows).

2 . Below are the two tables employee and department.You need to write SQL queries to get output of the below problems ?


emp_id  emp_name  dept_id emp_sal
1 Bijay Mohanty 100 100000
2 Ajay Mohanty 200 200000
3 Jyoti Panda 100 300000
4 Katrina K 300 400000
5 Deepika P 400 500000
6 Sonal C 100 100000


dept_id dept_name
100 Sales
200 IT
300 IT
400 Sales
500 Marketing
600 IT

(A) Write a SQL query to get second highest salary from employee table ?

Answer : select max(emp_sal) from employee where emp_sal not in (select max(emp_sal) from employee);


select emp_sal from employee where emp_sal in (select distinct emp_sal from employee order by emp_sal desc) and rownum>1 and rownum<3;