Wednesday, 28 September 2022
SQL Interview Questions
As SQL is quite vast so I will post interview questions on SQL query in three sets, below is the set-10:
1. Write An SQL Query To Print Details Of The EMPLOYEEs Whose FIRST_NAME Ends With ‘A’.
Select * from EMPLOYEE where FIRST_NAME like '%a';
2. Write An SQL Query To Print Details Of The EMPLOYEEs Whose FIRST_NAME Ends With ‘H’ And Contains Six Alphabets.
Select * from EMPLOYEE where FIRST_NAME like '_____h';
3. Write An SQL Query To Print Details Of The EMPLOYEEs Whose SALARY Lies Between 100000 And 500000.
Select * from EMPLOYEE where SALARY between 100000 and 500000;
4. Write An SQL Query To Print Details Of The EMPLOYEEs Who Have Joined In Feb’2014.
Select * from EMPLOYEE where year(JOINING_DATE) = 2014 and month(JOINING_DATE) = 2
5. Write An SQL Query To Fetch EMPLOYEE Names With Salaries >= 50000 And <= 100000.
Select FIRST_NAME, SALARY from EMPLOYEE where SALARY between 50000 And 100000.
6. Write An SQL Query To Fetch The No. Of EMPLOYEEs For Each Department In The Descending Order.
SELECT DEPARTMENT, count(EMPLOYEE_ID) No_Of_EMPLOYEEs
FROM EMPLOYEE
GROUP BY DEPARTMENT
ORDER BY No_Of_EMPLOYEEs DESC;
7. Write An SQL Query To Print Details Of The EMPLOYEEs Who Are Also Managers.
SELECT EMPLOYEE.EMPLOYEE_ID,EMPLOYEE.DEPARTMENT,EMPLOYEE.FIRST_NAME ,Title.EMPLOYEE_TITLE Title from EMPLOYEE Inner Join Title
on EMPLOYEE.EMPLOYEE_ID=Title.EMPLOYEE_Ref_ID where Title.EMPLOYEE_TITLE='Manager' order by EMPLOYEE_ID
8. Write An SQL Query To Fetch Duplicate Records Having Matching Data In Some Fields Of A Table.
SELECT EMPLOYEE_TITLE, AFFECTED_FROM, COUNT(*)
FROM Title
GROUP BY EMPLOYEE_TITLE, AFFECTED_FROM
HAVING COUNT(*) > 1;
9. Write An SQL Query To Show Only Odd Rows From A Table.
SELECT * FROM Emplyee WHERE MOD (EMPLOYEE_ID, 2) <> 0;
10. Write An SQL Query To Show Only Even Rows From A Table.
SELECT * FROM EMPLOYEE WHERE MOD (EMPLOYEE_ID, 2) = 0;
11. Write An SQL Query To Determine The Nth (Say N=5) Highest Salary From A Table.
SELECT Salary FROM EMPLOYEE ORDER BY Salary DESC LIMIT n-1,1;
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment