If you want to improve SQL skills, then install a SQL package like MySQL and start practicing with it. To get you started, we’ve outlined a few SQL query questions in this post. The interview questions for sql queries we’ve filtered out of interviews held by top IT MNC like Flipkart and Amazon. So you’ll gain real-time experience by going through them. Interview questions for sql queries is contain easy to hard variety of question and now a days windowing function is necessary in advance SQL queries
If you interested to grap a command on SQL ,we providing sql test questions and answers which is easy to help in crack interview exam and sql technical exam. Here we have example of emp and dept table in mysql . emp table in sql contain data of his employee . check out employee and department table queries in mysql
Here we can see data in emp table
empno |
ename |
job |
mgr |
hiredate |
sal |
comm |
deptno |
7369 |
SMITH |
CLERK |
7902 |
1993-06-13 |
800.00 |
0.00 |
20 |
7499 |
ALLEN |
SALESMAN |
7698 |
1998-08-15 |
1600.00 |
300.00 |
30 |
7521 |
WARD |
SALESMAN |
7698 |
1996-03-26 |
1250.00 |
500.00 |
30 |
7566 |
JONES |
MANAGER |
7839 |
1995-10-31 |
2975.00 |
|
20 |
7698 |
BLAKE |
MANAGER |
7839 |
1992-06-11 |
2850.00 |
|
30 |
7782 |
CLARK |
MANAGER |
7839 |
1993-05-14 |
2450.00 |
|
10 |
7788 |
SCOTT |
ANALYST |
7566 |
1996-03-05 |
3000.00 |
|
20 |
7839 |
KING |
PRESIDENT |
|
1990-06-09 |
5000.00 |
0.00 |
10 |
7844 |
TURNER |
SALESMAN |
7698 |
1995-06-04 |
1500.00 |
0.00 |
30 |
7876 |
ADAMS |
CLERK |
7788 |
1999-06-04 |
1100.00 |
|
20 |
7900 |
JAMES |
CLERK |
7698 |
2000-06-23 |
950.00 |
|
30 |
7934 |
MILLER |
CLERK |
7782 |
2000-01-21 |
1300.00 |
|
10 |
7902 |
|
ANALYST |
7566 |
1997-12-05 |
3000.00 |
|
20 |
7654 |
MARTIN |
SALESMAN |
7698 |
1998-12-05 |
1250.00 |
1400.00 |
30 |
Here we can see data in dept table
deptno |
dname |
location |
10 |
Accounting |
New York |
20 |
Research |
Dallas |
30 |
Sales |
Chicago |
40 |
Operations |
Boston |
Here we can see data in salgrade table
grade |
losal |
hisal |
1 |
700.00 |
1200.00 |
2 |
1201.00 |
1400.00 |
4 |
2001.00 |
3000.00 |
5 |
3001.00 |
99999.00 |
3 |
1401.00 |
2000.00 |
Below is syntex of creation of database -
DROP TABLE IF
EXISTS dept;
DROP TABLE IF EXISTS
salgrade;
DROP TABLE
IF EXISTS emp;
Below is syntex of creation of database
Below is syntex of insertion of data in dept ,emp and salgrade table-
insert into dept values
(20,'Research','
insert into dept values
(30,'Sales','
insert into dept values
(40,'Operations','
insert into emp values (7369,'SMITH','CLERK',7902,'93/6/13',800,0.00,20);
insert into emp values (7499,'ALLEN','SALESMAN',7698,'98/8/15',1600,300,30);
insert into emp values (7521,'WARD','SALESMAN',7698,'96/3/26',1250,500,30);
insert into emp values (7566,'JONES','MANAGER',7839,'95/10/31',2975,null,20);
insert into emp values (7698,'BLAKE','MANAGER',7839,'92/6/11',2850,null,30);
insert into emp values (7782,'CLARK','MANAGER',7839,'93/5/14',2450,null,10);
insert into emp values (7788,'SCOTT','ANALYST',7566,'96/3/5',3000,null,20);
insert into emp values (7839,'KING','PRESIDENT',null,'90/6/9',5000,0,10);
insert into emp values (7844,'TURNER','SALESMAN',7698,'95/6/4',1500,0,30);
insert into emp values (7876,'ADAMS','CLERK',7788,'99/6/4',1100,null,20);
insert into emp values (7900,'JAMES','CLERK',7698,'00/6/23',950,null,30);
insert into emp values (7934,'MILLER','CLERK',7782,'00/1/21',1300,null,10);
insert into
emp values (7902,'
insert into emp values (7654,'MARTIN','SALESMAN',7698,'98/12/5',1250,1400,30);
insert into salgrade values (1,700,1200);
insert into salgrade values (2,1201,1400);
insert into salgrade values (3,1401,2000);
insert into salgrade values (4,2001,3000);
insert into salgrade values (5,3001,99999);
Let start with question and answer -
Select substring(ename ,1,3) from emp;
Select LTRIM(ename) from emp;
Select LTRIM(job ) from emp;
Select distinct length(job ) from emp ;
Select * from emp order by ename asc;
Select * from emp where ename in ('Vipul','Satish');
selet sum(Sal) ,deptno from emp group by deptno having sum(sal) > 5000
select ename ,job, salary from emp b inner join (select sum(Sal) as salary ,job from emp group by job ) a on b.job = a.job
select b.dname , b.location form emp a left outer join dept b on b.deptno = a.deptno where a.deptno is null
Select * from emp where job like 'CLERK%';
Select * from emp where ename like '%a%';
Select * from emp where ename like '%a';
Select * from emp where ename like '_____h';
Select * from emp where sal between 100000 and 500000;
Select * from emp where year(hiredate) = 2014 and month(hiredate) = 2;
SELECT COUNT(*) FROM emp WHERE DEPARTMENT = 'CLERK';
SELECT DEPARTMENT, count(WORKER_ID) No_Of_Workers FROM worker GROUP BY DEPARTMENT ORDER BY No_Of_Workers DESC;
SELECT ename , COUNT(*) FROM emp GROUP BY ename HAVING COUNT(*) > 1;
SELECT * INTO empClone FROM Worker;
SELECT * INTO empClone FROM Worker WHERE 1 = 0;
(SELECT * FROM emp) INTERSECT (SELECT * FROM EmpClone);
SELECT CURDATE();
SELECT NOW();
SELECT getdate();
SELECT SYSDATE FROM DUAL;
SELECT * FROM Worker ORDER BY Salary DESC LIMIT 10;
SELECT TOP 10 * FROM Worker ORDER BY Salary DESC;
SELECT * FROM (SELECT * FROM Worker ORDER BY Salary DESC) WHERE ROWNUM <= 10;
SELECT distinct * FROM Worker OR SELECT count(*),ename FROM Worker group by ename The SELECT DISTINCT statement is used to return only distinct (different) values. Inside a table, a column often contains many duplicate values; In Group by taking column name and provide us disctinct result based on Column value.
RENAME TABLE emp TO emp_old, emp_new TO emp; Or An alias is created with the AS keyword. SELECT ename AS EmployeeName FROM Emp
In a SQL database, a schema is represent a list of logical structures of data. A database user owns the schema,It can be single or multiple . depend upon requirment . which has the same name as the database manager. As of SQL Server 2005, a schema is an individual entity (container of objects) distinct from the user who constructs the object.
No ,It is contain virtual represtation of data, with cutomize out put.
Answer: Yes, A View is based on another View.
Answer: A CTE or common table expression is an expression that contains a temporary result set which is defined in a SQL statement.
Ans. The required query is: SELECT t.dname , t.ename, t.sal as salary, from(SELECT max(sal) as TotalSalary,dname from dept group by deptno ) as TempNew Inner Join emp t on TempNew.deptno =t.deptno and TempNew.TotalSalary=t.sal;
Ans. SELECT distinct Salary from emp a WHERE 3 >= (SELECT count(distinct Salary) from emp b WHERE a.Salary <= b.Salary) order by a.Salary desc;
Answer SELECT distinct sal from emp a WHERE 3 >= (SELECT count(distinct Salary) from worker b WHERE a.Salary >= b.Salary) order by a.Salary desc;
Answer SELECT distinct Salary from worker a WHERE n >= (SELECT count(distinct Salary) from worker b WHERE a.Salary <= b.Salary) order by a.Salary desc;
Answer: SELECT ename, sal from emp WHERE sal=(SELECT max(sal) from emp);
Answer : select dname from empdept where deptno in (select dept from emp where empid>103)
Answer :select ename from emp where mgr =(select empid from employee where empname='shubham')
Answer : select ename from emp where empno =(select mgr from dept where dname='hr')
Answer : select * from emp where deptno in(select deptno from dept where dname='development')
Ans. We can use the TRUNCATE query to delete data from the SQL database table. TRUNCATE TABLE emp;
DELETE FROM StudentStipend WHERE StudId IN ( SELECT StudId FROM StudentStipend GROUP BY Project, Stipend HAVING COUNT(*) > 1));
Ans. We can perform the required operation using the SELECT INTO query. SELECT * INTO newTable FROM StudentDetails;
Ans. SQL queries for various Databases are as described below. SQL Query In Oracle SELECT SYSDATE FROM DUAL;
SELECT getdate();
SELECT NOW();
SELECT ename FROM emp ORDER BY ename DESC LIMIT N-1,1;
Answer: Select to_date (Hire_date,’DD-MON-YYYY’) Date_Format from Employee;
Ans. SQL queries for fetching top n records using LIMIT for various Databases are as described below. In MySQL in emp table SELECT * FROM emp ORDER BY ename DESC LIMIT N; In SQL server using the TOP command SELECT TOP N * FROM emp ORDER BY ename DESC
Here in this Article We can see sql questions practice Details of list of basic sql practical questions . sql query questions is help you to start your learning in sql . We also provide you question of emp and dept table in mysql. sql queries interview questions