In this post you will learn SQL Query interview Questions for freshers and Experienced candidates. These are Frequently
asked basic and advanced SQL Queries Interview Questions and Answers
with Examples for Business Analyst, Data Analyst, DBA, Freshers and
Experienced Java, PHP, Dot Net programmers in Oracle, MySQL and MS SQL
Database.
Consider this table to use in our queries:
Table Name : Employee
create table employee
(
Emp_Id int,
First_Name varchar2(20),
Last_Name varchar2(20),
salary number,
joining_date date,
Department varchar2(20));
After inserting some data into employee table the following result will come.
Result:
Table Name : Incentives
create table Incentives
(
Emp_Id int,
Incentive_Date date,
Incenttive_amount number);
Result:
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 in upper case
select upper(first_name)from employee;
4) Get First_Name from employee table in lower case
select lower(first_name) from employee;
5) Get unique DEPARTMENT from employee table
select distinct DEPARTMENT from Employee;
6) Get FIRST_NAME ,Joining year,Joining Month and Joining Date from employee table
Select FIRST_NAME, to_char(joining_date,'YYYY') Join_Year ,
to_char(joining_date,'Mon') join_Month,
to_char(joining_date,'dd') join_date from EMPLOYEE;
7) Get all employee details from the employee table order by First_Name Ascending
Select * from employee order by FIRST_NAME asc;
8) Get all employee details from the employee table order by First_Name Ascending and Salary descending
Select * from employee order by FIRST_NAME asc,SALARY desc;
9) Get employee details from employee table whose employee name is “John”
Select * from EMPLOYEE where FIRST_NAME='pavan';
10) Get employee details from employee table whose Salary greater than15000
Select * from EMPLOYEE where Salary >15000;
12) Get employee details from employee table whose Salary between 15000 and 25000
Select * from EMPLOYEE where Salary between 15000 and 25000;
13) Get employee details from employee table whose joining year is “2015”
Select * from EMPLOYEE where to_char(joining_date,'YYYY')='2015';
14) Get employee details from employee table whose joining month is “January”
Select * from EMPLOYEE where to_char(joining_date,'MM')='01' ;
(or)
Select * from EMPLOYEE where to_char(joining_date,'Mon')='Jan';
15) Get difference between JOINING_DATE and INCENTIVE_DATE from employee and incentives tableSelect FIRST_NAME,INCENTIVE_DATE ,JOINING_DATE from employee a inner join incentives B on A.EMP_ID=B.EMP_ID;
SQL Queries in Oracle:
select sysdate from dual;
SQL Queries in SQL Server:
select getdate();
SQL Query in MySQL:
select now();
16) Get department,total salary with respect to a department from employee table.
Select DEPARTMENT,sum(SALARY) Total_Salary from employee group by department;
17) Get department,total salary with respect to a department from employee table order by total salary descendingSelect DEPARTMENT,sum(SALARY) Total_Salary from employee group by DEPARTMENT order by Total_Salary desc;
18) Get department wise average salary from employee table order by salary ascending
select DEPARTMENT,avg(SALARY) AvgSalary from employee group by DEPARTMENT order by AvgSalary asc;
19) select first_name, incentive amount from employee and incentives table for those employees who have incentives
Select FIRST_NAME,INCENTTIVE_AMOUNT from employee a inner join incentives B on A.EMP_ID=B.EMP_ID;
20) select first_name, incentive amount from employee and incentives table for those employees who have incentives and incentive amount greater than 5000
Select FIRST_NAME,INCENTTIVE_AMOUNT from employee a inner join incentives B on A.EMP_ID=B.EMP_ID and INCENTTIVE_AMOUNT >5000;
I hope you enjoy this post and share this to your friends and social media to reach more people.keep follow me for latest updates
Consider this table to use in our queries:
Table Name : Employee
create table employee
(
Emp_Id int,
First_Name varchar2(20),
Last_Name varchar2(20),
salary number,
joining_date date,
Department varchar2(20));
After inserting some data into employee table the following result will come.
Result:
Table Name : Incentives
create table Incentives
(
Emp_Id int,
Incentive_Date date,
Incenttive_amount number);
Result:
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 in upper case
select upper(first_name)from employee;
4) Get First_Name from employee table in lower case
select lower(first_name) from employee;
5) Get unique DEPARTMENT from employee table
select distinct DEPARTMENT from Employee;
6) Get FIRST_NAME ,Joining year,Joining Month and Joining Date from employee table
Select FIRST_NAME, to_char(joining_date,'YYYY') Join_Year ,
to_char(joining_date,'Mon') join_Month,
to_char(joining_date,'dd') join_date from EMPLOYEE;
7) Get all employee details from the employee table order by First_Name Ascending
Select * from employee order by FIRST_NAME asc;
8) Get all employee details from the employee table order by First_Name Ascending and Salary descending
Select * from employee order by FIRST_NAME asc,SALARY desc;
9) Get employee details from employee table whose employee name is “John”
Select * from EMPLOYEE where FIRST_NAME='pavan';
10) Get employee details from employee table whose Salary greater than15000
Select * from EMPLOYEE where Salary >15000;
12) Get employee details from employee table whose Salary between 15000 and 25000
Select * from EMPLOYEE where Salary between 15000 and 25000;
13) Get employee details from employee table whose joining year is “2015”
Select * from EMPLOYEE where to_char(joining_date,'YYYY')='2015';
14) Get employee details from employee table whose joining month is “January”
Select * from EMPLOYEE where to_char(joining_date,'MM')='01' ;
(or)
Select * from EMPLOYEE where to_char(joining_date,'Mon')='Jan';
15) Get difference between JOINING_DATE and INCENTIVE_DATE from employee and incentives tableSelect FIRST_NAME,INCENTIVE_DATE ,JOINING_DATE from employee a inner join incentives B on A.EMP_ID=B.EMP_ID;
SQL Queries in Oracle:
select sysdate from dual;
SQL Queries in SQL Server:
select getdate();
SQL Query in MySQL:
select now();
16) Get department,total salary with respect to a department from employee table.
Select DEPARTMENT,sum(SALARY) Total_Salary from employee group by department;
17) Get department,total salary with respect to a department from employee table order by total salary descendingSelect DEPARTMENT,sum(SALARY) Total_Salary from employee group by DEPARTMENT order by Total_Salary desc;
18) Get department wise average salary from employee table order by salary ascending
select DEPARTMENT,avg(SALARY) AvgSalary from employee group by DEPARTMENT order by AvgSalary asc;
19) select first_name, incentive amount from employee and incentives table for those employees who have incentives
Select FIRST_NAME,INCENTTIVE_AMOUNT from employee a inner join incentives B on A.EMP_ID=B.EMP_ID;
20) select first_name, incentive amount from employee and incentives table for those employees who have incentives and incentive amount greater than 5000
Select FIRST_NAME,INCENTTIVE_AMOUNT from employee a inner join incentives B on A.EMP_ID=B.EMP_ID and INCENTTIVE_AMOUNT >5000;
I hope you enjoy this post and share this to your friends and social media to reach more people.keep follow me for latest updates
No comments:
Post a Comment