Top 25 SQL Query Interview Questions and Answers

  • Share
  • 13965
  • 0
  • Share
SQL Query Interview Questions and Answers

Are you searching for SQL Query Interview Questions & Answers for fresher and experienced candidates? Here in this article, we have mentioned some of the top SQL query interview questions to pass the job interview panel.

SQL Query Interview Questions & Answers


  1. How will you write an SQL Query to fetch the count of the employee working in project “Q1”?

Here, we would be using comprehensive function calculation() with the SQL where the phrase:

  • SELECT COUNT(*)
  • FROM Employee Salary
  • WHERE Project = “Q1”;
  1. Mention an SQL Query to find the employee id whose salary lies in the range of 16000 and 50000?

Here, we can utilize the ‘Between’ operative with a were part.

SELECT EmpId, Salary

FROM Employee Salary

WHERE Salary BETWEEN 16000 AND 50000;

  1. Write an SQL Query to fetch “LAST_NAME” from employee table in upper case?

The necessary query is:

Select upper (LAST_NAME) from Employee;

  1. Write a SQL Query find a number of workers according to gender whose DOB is between 01/01/1986 to 31/12/1998?

SELECT COUNT (*), sex from Workers WHERE DOB BETWEEN '01/01/1986' AND '31/12/1998' group by.

  1. Write an SQL Query to display the total salary of each worker adding the salary with variable use?

Here, we can merely use the ‘+’ operative in SQL.

SELECT EmpId,

Salary Variable as Total Salary

FROM Worker Salary;

  1. Write an SQL query to fetch all the students from table Students who either live in Delhi or studying a course with Course id -440?

This question requires us to please either of the conditions employees living in ‘Delhi’ and studying a course with CourseId ‘440’. So, we will utilize the OR operative here.

SELECT StId, City, CourseId

FROM Students Details

WHERE City='Delhi' OR CourseId='440';

  1. Write an SQL Query to find the maximum, minimum and average marks of the students?

We can use the combined meaning of SQL to bring the max, min and average values:

SELECT Max (Marks),

Min (Marks),

AVG (Marks)

FROM Student Marks;

  1. Write an SQL Query to fetch the various projects available from the worker salary table?

While referring to the Worker Salary table, we can notice that this table contains project values matching to each employee, or we can articulate that we will have replacement project values while selecting Project values from this bench. So, we will use the separate clause to get the sole values of the Project.

SELECT DISTINCT (Project)

FROM Worker Salary;

  1. Write an SQL Query to fetch the Worker ID and Full Name of all the workers working under manager Id- 221?

We can use the Worker Details table to bring the employee details with a where the section for the manager.

SELECT WorkId, Full Name

FROM Worker Details

WHERE ManagerId = 221;

  1. Mention a SQL Query to obtain the employee's name starts with any two characters, followed by a text “sh” and ending with any sequence of characters?

For this interview question, we can produce an SQL query using like a worker with ‘_’ and ‘%’ wild card characters, where ‘_’ matches a particular character and ‘%’ matches ‘0 or various characters’.

SELECT Full Name

FROM Employee Details

WHERE Full Name LIKE ‘__sh%’;

  1. Write an SQL Query to fetch entries that are present in one table but not in another table?

SQL Server – Using MINUS- worker-

SELECT * FROM Employee Salary

MINUS

SELECT * FROM Manager Salary;

MySQL – Since MySQL doesn’t have MINUS operator so we can use LEFT join-

SELECT EmployeeSalary.*

FROM Employee Salary

LEFT JOIN

Manager Salary USING (EmpId)

WHERE ManagerSalary.EmpId IS NULL;

  1. Write an SQL Query to fetch the student's full names and replace the space with ‘-‘?

Using ‘restore’ function-

SELECT REPLACE (Full Name, ' ', '-')

FROM Student Details;

  1. Write an SQL Query to print both the Worker ID and Manager ID together?

Here we can employ the CONCAT authority.

SELECT CONCAT (EmpId, ManagerId) as NewId

FROM Employee Details;

  1. Write an SQL Query to lower case the name of the student and upper case the city values?

We can employ SQL Upper and Lower functions to attain future results.

SELECT LOWER (Full Name), UPPER (City)

FROM Student Details;

  1. Write an SQL Query to update the worker names by removing leading and trailing spaces?

Using ‘Update’ authority with ‘LTRIM’ and ‘RTRIM’ meaning.

UPDATE Worker Details

SET Full Name = LTRIM (RTRIM (Full Name));

  1. Obtain all the workers who are not working on any project?

This is one of the essential questions in which the interviewer wants to observe if the person knows about the usually used – Is NULL operator.

SELECT EmpId

FROM Worker Salary

WHERE Project IS NULL;

  1. Mention the SQL Query to find the current date and time?

MySQL-

SELECT NOW ();

SQL Server-

SELECT get date ();

Oracle-

SELECT SYSDATE FROM DUAL;

  1. Write an SQL Query to display the LAST_NAME from employee table after removing white spaces from the right side?

The necessary query is:

Select RTRIM (LAST_NAME) from Employee;

  1. Write an SQL Query to show the department from employee table after removing white space from the left side?

The requisite query is:

Select LTRIM (DEPARTMENT) from Employee;

  1. Mention an SQL Query to print the FIRST NAME from employee table after replacing “a” with “A”?

The obligatory query is:

Select REPLACE (FIRST_NAME,'a','A') from Employee;

  1. Write an SQL Query to show all employee details from the employee table order by LAST_ NAME Ascending?

The necessary query is:

Select * from Employee order by LAST_NAME asc;

  1. Write an SQL Query to show details of the employees whose LAST_NAME contains “j”?

The compulsory query is:

Select * from Worker where LAST_NAME like '%j%';

  1. Write an SQL Query to show details of the workers whose LAST_NAME ends with “a” and contain six alphabets?

The compulsory query is:

Select * from Worker where LAST_NAME like '_____a';

  1. Write an SQL Query to show details of the employees who have joined in August 2017?

The requisite query is:

Select * from Worker where year (JOINING_DATE) = 2017 and month (JOINING_DATE) = 8;

  1. Write an SQL Query to show details of the employees who are also managers?

The obligatory query is:

SELECT DISTINCT W.FIRST_NAME, T.WORKER_TITLE

FROM Worker W

INNER JOIN Title T

ON W.WORKER_ID = T.WORKER_REF_ID

AND T.WORKER_TITLE in ('Manager');

So, above are the mentioned interview questions for SQL Jobs, candidates should go through it and fetch more interview questions to clear their job interview.

Related Articles:

Vidhi Shukla

Related Articles

New to Shine?Get access to over 5K+ Jobs
Posted DailyAlready Registered? Login Here
New to Shine

Popular Courses

Course
Backend Developer in Java

4.5

Backend Developer in Java

TestPrepTraining

Duration: 51 Hours|Mode: Online

Course
Backend Developer in Python

4.5

Backend Developer in Python

TestPrepTraining

Duration: 20 Hours|Mode: Online

Course
Backend Developer in Node.js

4.5

Backend Developer in Node.js

TestPrepTraining

Duration: 41 Hours|Mode: Online

View All
New to Shine
New to Shine? Get access to over 5K+ Jobs Posted Daily.Already Registered?Login Here