SQL query interview questions for both freshers and experienced.

Hey, guys in this article I am going to tell you the most important SQL query interview questions along with SQL query, it will helpful for both freshers and experienced.

Table Name: user 1

Table Name:user 2

Table Name:user 3

Write a SQL query to join two tables using an inner join?

If you run this below query along with where clause on the PHPMyAdmin, it will execute but it will not execute on the SQL server, we need to use ON instead where clause.

select * from user1 inner join user2 where user1.id=user2.id

select * from user1 inner join user2 ON user1.id=user2.id

Write a SQL query to fetch specific columns record using inner join?

select job as JOB,father as FATHER from user1 JOB inner join user2 FATHER where JOB.id=FATHER.id

Write a SQL query to join three tables?

select job as A,father as B,name as C from user1 A inner join user2 B INNER join user3 C where A.id=B.id and B.id=C.id

Write a SQL query of self join?

select A.job as JOB,B.job as JOB1 from user1 A,user1 B where A.id=B.id

Most important java program interview Questions.

Write a SQL query of Left join?

select * from user1 left join user2 on user1.id=user2.id

Write a SQL query of Right join?

select * from user1 right join user2 on user1.id=user2.id

Write a insert Query?

insert into user1(id,job,salary,location) VALUES(”,’QA’,6000,’Canada’)

Write a update Query?

UPDATE user1 set job=’er’ where id=12

Write a SQL query of delete?

Delete from user1 where id=1

Write a SQL query of truncate?

TRUNCATE table user1

Write a sql query of drop?

drop table user1

Write a SQL query to add the column in the table?

alter table user1 add test varchar(200)

Write a SQL query to delete the column from the table?

alter table user1 drop test

Write a SQL query of Max salary?

select max(salary) from user1

Write a SQL query of Min salary?

select min(salary) from user1

Write a SQL query of AVG salary?

select avg(salary) from user1

Write a SQL query of 2nd highest salary?

SELECT max(salary) from user1 where salary not in(SELECT max(salary) from user1)

Write a SQL query of 2nd highest salary in 5 records via use of limit?

SELECT DISTINCT salary from user1 ORDER by salary limit 3,1

Write a SQL query to replace the value/data in the table?

UPDATE user1 set job=REPLACE(job,’footebal’,’football’)

Write a SQL query to interchange the value in the table?

UPDATE user1 set job=if(job=’football’,’hockey’,’football’)

Write a SQL query to find the unique value from the job column in the table user1?

SELECT DISTINCT job from user1

Write a SQL query to fetch first 3 characters from the job column in the table user1?

SELECT substring(job,1,3) from user1

Write a SQL query to print the length along with unique value from the job column in the table user1?

SELECT DISTINCT length(job) from user1

Write a SQL query to print detail of location with the job as ‘hockey’ and ‘football’ from the table user1?

SELECT location from user1 where job IN(‘hockey’,’football’)

Write a SQL query to print detail of location excluding the job as ‘hockey’ and ‘football’ from the table user1?

SELECT location from user1 where job NOT IN(‘hockey’,’football’)

Table Name: EmpSal

Table Name: EmpDtl

Software Testing Question Bank for interview

Write a SQL query to fetch the count of employees working in project=’Project1′ from the EmpSal table?

SELECT count(*) from EmpSal where Project=’Project1′

Write a SQL query to fetch the name of employee having salary greater than or equal to 20000 and less than or equal to 5000?

SELECT FullName from EmpDtl where EmpId IN(SELECT EmpId from EmpSal WHERE Salary BETWEEN 5000 AND 20000)

Write a SQL query to fetch the project wise count of employees sorted by projects and count in desc order?

SELECT Project,count(EmpId) empcount from EmpSal group by Project order by empcount DESC

Write a SQL query to fetch all employee record from EmpDtl table having salary record in EmpSal table?

SELECT * from EmpDtl where EXISTS(SELECT * from EmpSal where EmpDtl.EmpId=EmpSal.EmpId)

Write a SQL query to fetch duplicate records from the table?

SELECT EmpId,Project,Salary,COUNT(*) from EmpSal group BY EmpId,Project,Salary HAVING COUNT(*)>1

Write a SQL query to fetch the odd rows from the table?

SELECT * from EmpSal where EmpId IN(SELECT EmpId FROM EmpSal where EmpId%2<>0)

Write a SQL query to fetch the even rows from the table?

SELECT * from EmpSal where EmpId IN(SELECT EmpId FROM EmpSal where EmpId%2=0)

Please drop the comment regarding any query or for any suggestion/correction!

  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  

Leave a Comment

fourteen + 8 =