SQL Query Interview Questions

0
2982
SQL Query Interview Questions

Let us try to answer common interview questions using below two tables – Employee and Incentive

SQL Basics

1. Get all employee details from the employee table?

SELECT * FROM EMPLOYEE;

2. Get First_Name, Last_Name from employee table?

SELECT FIRST_NAME, LAST_NAME FROM EMPLOYEE ;

3. Get First_Name from employee table using alias name “Employee Name”?

SELECT FIRST_NAME “EMPLOYEE NAME” FROM EMPLOYEE;

4. Get First_Name from employee table in upper case?

SELECT UPPER (FIRST_NAME) FROM EMPLOYEE;

5. Get FIRST_NAME from employee table in lower case?

SELECT LOWER (FIRST_NAME) FROM EMPLOYEE;

6. Get unique DEPARTMENT from employee table?

SELECT DISTINCT DEPARTMENT FROM EMPLOYEE;

7. Select first 3 characters of FIRST_NAME from EMPLOYEE?

SELECT SUBSTR (FIRST_NAME, 0, 3) FROM EMPLOYEE;

8. Get position of ‘o’ in name ‘John’ from employee table?

SELECT INSTR (FIRST_NAME,'o') FROM EMPLOYEE WHERE FIRST_NAME='John';

9. Get FIRST_NAME from employee table after removing white spaces from right side?

SELECT RTRIM (FIRST_NAME) FROM EMPLOYEE;

10. Get FIRST_NAME from employee table after removing white spaces from left side?

SELECT LTRIM (FIRST_NAME) FROM EMPLOYEE;

11. Get length of FIRST_NAME from employee table?

SELECT LENGTH (FIRST_NAME) FROM EMPLOYEE;

12. Get First_Name from employee table after replacing ‘o’ with ‘$’?

SELECT FIRST_NAME, REPLACE (FIRST_NAME,'o','$') FROM EMPLOYEE;

13. Get First_Name and Last_Name as single column from employee table separated by a ‘_’?

SELECT FIRST_NAME|| '_' ||LAST_NAME FROM EMPLOYEE;

14. Get FIRST_NAME, Joining year, Joining Month and Joining Date from employee table?

SELECT FIRST_NAME, 
	TO_CHAR(JOINING_DATE,'YYYY') JOINYEAR ,
	 TO_CHAR(JOINING_DATE,'MON'),
	  TO_CHAR(JOINING_DATE,'DD')          FROM         EMPLOYEE;