MySQL Interview Questions

SQL INTERVIEW QUESTION PART-2

MySQL Interview Questions

List of most frequently asked MySQL Interview Questions. Questions from basics to advance level with the solution.

 

51) Display the name of the employee who earns the highest salary.

SQL>select ename from emp where sal= (select max (sal) from emp);

 

52) Display the employee number and name for employees working as clerks and earning the highest salary among clerks.

SQL>select empno, ename from emp where job='CLERK' and sal= (select max (sal) from emp where job='CLERK');

 

53) Display the names of the salesman who earns a salary more than the highest salary of any clerk.

SQL>select ename, sal from emp where job='SALESMAN' and sal> (select max (sal) from emp where job='CLERK');

 

54) Display the names of clerks who earn a salary more than the lowest salary of any salesman.

SQL>select ename from emp where job='CLERK' and sal> (select min (sal) from emp where job='SALESMAN');

 

55) Display the names of employees who earn a salary more than that of Jones or that of salary greater than that of Scott.

SQL>select ename, sal from emp where sal> (select sal from emp where ename='JONES') and sal> (select sal from emp where ename='SCOTT');

 

56) Display the names of the employees who earn the highest salary in their respective departments.

SQL>select ename, sal, deptno from emp where sal in (select max (sal) from emp group by deptno);

 

57) Display the names of the employees who earn the highest salaries in their respective job groups.

SQL>select ename, sal, job from emp where salin (select max (sal) from emp group by job) 

 

58) Display the employee’s names who are working in the accounting department.

SQL>select ename from emp where deptno= (select deptno from dept where dname='ACCOUNTING') 

 

59) Display the employees names who are working in Chicago.

SQL>select ename from emp where deptno= (select deptno from dept where LOC='CHICAGO') 

 

60) Display the Job groups having a total salary greater than the maximum salary for managers.

SQL>SELECT JOB, SUM (SAL) FROM EMP GROUP BY JOBHAVING SUM (SAL) > (SELECT MAX (SAL) FROM EMP WHERE JOB='MANAGER');

 

61) Display the names of employees from department number 10 with a salary greater than that of any employee working in other departments.

SQL>select ename from emp where deptno=10 and sal>any (select sal from emp where deptno not in 10).

 

62) Display the names of the employees from department number 10 with salary greater than that of all employees working in other departments.

SQL>select ename from emp where deptno=10 and sal>all (select sal from emp where deptno not in 10).

 

63) Display the names of the employees in Uppercase.

SQL>select upper (ename) from emp;

 

64) Display the names of the employees in Lowercase.

SQL>select lower (ename) from emp;

 

65) Display the names of the employees in the proper case.

SQL>select initcap (ename) from emp;

 

66) Display the length of your name using the appropriate function.

SQL>select length ('name') from dual;

 

67) Display the length of all the employee names.

SQL>select length (ename) from emp;

 

68) Select the name of the employee to concatenate with the employee number.

SQL>select ename||empno from emp;

 

69) User appropriate function and extract 3characters starting from 2characters from the following string ‘Oracle’. I.e. the output should be ‘ac’.

SQL>select substr ('oracle', 3, 2) from dual

 

70) find the First occurrence of character ‘a’ from the following string i.e. ‘Computer Maintenance Corporation’.

SQL>SELECT INSTR ('Computer Maintenance Corporation’,’ a', 1) FROM DUAL

 

71) Replace every occurrence of the alphabet A with B in the string Allens (use translate function)

SQL>select translate ('Allens','A','B') from dual

 

72) Display the information from the emp table. Where the job manager is found it should be displayed as boos (Use replace function).

SQL>select replace (JOB,'MANAGER','BOSS') FROM EMP;

 

73) Display empno, ename, deptno from emp table. Instead of display department numbers display the related department name (Use decode function).

SQL>select empno, ename, decode (deptno, 10,'ACCOUNTING', 20,'RESEARCH', 30,'SALES', 40,'OPRATIONS') from emp;

 

74) Display your age in days.

SQL>select to date (sysdate) -to date ('10-sep-77') from dual

 

75) Display your age in months.

SQL>select months between (sysdate,'10-sep-77') from dual

 

76) Display the current date as 15th August Friday Nineteen Ninety Seven.

SQL>select to char (sysdate,'ddth Month day year') from dual

 

78) Scott has joined the company on Wednesday 13th August nineteen ninety.

SQL>select ENAME||' HAS JOINED THE COMPANY ON'||to_char (HIRE DATE,'dayddth Month year') from EMP;

 

79) Find the date for the nearest Saturday after the current date.

SQL>SELECT NEXT_DAY (SYSDATE,'SATURDAY') FROMDUAL;

 

80) Display current time.

SQL>select to_char (sysdate,'hh:MM:ss') from dual.

 

81) Display the date three months before the current date.

SQL>select add months (sysdate, 3) from dual;

 

82) Display the common jobs from departments number 10 and 20.

SQL>select job from emp where deptno=10 and jobin (select job from emp where deptno=20);

 

83) Display the jobs found in departments 10 and20 Eliminate duplicate jobs.

SQL>select distinct (job) from emp where deptno=10or deptno=20orselect distinct (job) from emp where deptno in (10, 20);

 

84) Display the jobs which are unique to department 10.

SQL>select distinct (job) from emp where deptno=10

 

85) Display the details of those who do not have any person working under them.

SQL>select e.ename from emp, emp e whereemp.mgr=e.empno group by e.ename having count (*) =1;

 

86) Display the details of those employees who are in the sales department and grade is 3.

SQL>select * from emp where deptno= (selectdeptno from dept where dname='SALES') and sal between (select losal from salgrade where grade=3) and (select hisal from salgrade where grade=3);

 

87) Display those who are not managers and who are managers, anyone.

i) Display the managers’ names.

SQL>select distinct (m.ename) from emp e, emp mwhere m.empno=e.mgr;

ii) Display the who are not managers.

SQL>select ename from emp where ename notin (select distinct (m.ename) from emp e, emp m where m.empno=e.mgr);

 

88) Display those employees whose name contains not less than 4characters.

SQL>select ename from emp where length (ename) >4;

 

89) Display those departments whose names start with “S” while the location name ends with “K”.

SQL>select dname from dept where dname like 'S%'and loc like '%K';

 

90) Display those employees whose manager name is JONES.

SQL>select p.ename from emp e, emp p where e.empno=p.mgr and e.ename='JONES';

 

91) Display those employees whose salary is more than 3000 after giving20% increment.

SQL>select ename, sal from emp where (sal+sal*.2) >3000;

92) Display all employees while their dept names.

SQL>select ename, dname from emp, dept where emp.deptno=dept.deptno;

 

93) Display ename who are working in the sales dept.

SQL>select ename from emp where deptno= (select deptno from dept where dname='SALES');

 

94) Display employee name, deptname, salary, and comm. for those Sal in between2000 to 5000 while the location is Chicago.

SQL> select empno, ename, deptno from emp where deptno= (select deptno from dept where loc='CHICAGO') and sal between 2000 and 5000;

 

95) Display those employees whose salary greater than their manager’s salary.

SQL>select * from emp e where sal> (select sal from emp where empno=e.mgr);

 

96) Display those employees who are working in the same dept where his managers working.

SQL>select * from emp e where deptno = (select deptno from emp where empno=e.mgr);

 

97) Display those employees who are not working under any manager.

SQL>select * from emp where mgr is null or empno=mgr;

 

98) Display grade and employees name for the dept no 10 or 30 but the grade is not 4, while joined the company before 31-dec-82.

SQL>select empno, ename, sal, deptno, hiredate, grade from emp e, salgrade swhere e.sal>=s.losal and e.sal<=s.hisal and deptno in (10, 30) andgrade<>4 and hiredate<'01dec-1981';

 

99) Update the salary of each employee by 10% increments that are not eligible for commission.

SQL> update emp set sal=sal+ (sal*10/100) where comm is null;

 

100) delete those employees who joined the company before 31-dec-82 while their dept location is ‘NEW YORK’ or ‘CHICAGO’.

SQL> delete from emp where hiredate<'31-dec-1982' and deptno in (select deptno from dept where loc in ('NEW YORK','CHICAGO'));

 

Above are the most asked MySQL Interview Questions, also visit tricky SQL queries for interview.

Check Database Testing Interview Questions

Wikipedia SQL

1 thought on “MySQL Interview Questions”

Leave a Comment

Your email address will not be published.