Page Nav

HIDE
Friday, May 2

Pages

Breaking News:
latest

SQL tricky joins schema-based interview questions & Answers

Latest SQL JOINS interview solutions  Most frequently asked SQL JOINS interview questions Write an  SQL query to display: #JOIN Q.NO 1 The e...

Latest SQL JOINS interview solutions 





Most frequently asked SQL JOINS interview questions


Write an  SQL query to display:

#JOIN Q.NO 1

The employee ID, employee name, and basic pay of all employees under the employee category 'A'.

Your output should contain 3 columns in the below-mentioned order.
EmpID EmpName Basic
 

CODE

SELECT empid, empname, basic FROM employee_info e JOIN
salary_info s ON e.employee_category = s.employee_category
WHERE s.employee_category = 'A'



Write an Oracle SQL query to display:

#JOIN Q.NO 2

The employee IDemployee name, deptid, and deptname  of all employees. Their respective location is 'CHENNAI'.

Your output should contain 3 columns in the below-mentioned order.
EmpID EmpName Deptid and Deptname

SELECT empid, empname, deptid, deptname FROM employee_info 
JOIN dept_info USING(deptid) WHERE location = 'CHENNAI'

Write an SQL query to display.

#JOIN Q.NO 3

The employee ID, employee name, department ID, department name, and net pay of all employees who have been allotted some department and have drawn the highest salary (net pay) in the month of April 2012.

Hint: For example, if there are 10 employees out of which 3 employees have drawn the highest salary in the month of April 2012, where the highest salary is RS.1000, the records of all three employees need to be displayed.

Note: The month names are abbreviated.
For example, January is stored as "JAN", February is stored as "FEB", March is stored as "MAR", and so on.

CODE

SELECT empid, empname, deptid, deptname, netpay
 From employee_info RIGHT JOIN dep_info USING(deptid) JOIN
emp_payroll USING(empid) WHERE netpay IN
                                 (SELECT MAX(netpay) FROM 
                                    emp_payroll WHERE month =  'APR' AND year  = 2012)
                                     AND deptname IS NOT NULL