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 ?
(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;