Saturday

Top 10 Frequently asked SQL Query Interview Questions

Introduction

In this article, I am giving a few cases of SQL inquiries which is frequently approached when you go for a programming interviews, having maybe a couple year experience on this field. Regardless of whether you go for Java engineer position, QA, BA, supports professional,project manager or some other specialised position, may questioner anticipate that you will answer essential inquiries from Database and SQL. It's likewise clear that in the event that you are working from maybe a couple a long time on any venture there is great possibility that you run over to deal with database, composing SQL queries to insert, refresh, erase and select records. One straightforward yet viable approach to check competitor's SQL aptitude is by soliciting these sorts from basic inquiry. They are neither  complex nor big, yet they cover all key idea a software engineer should think about SQL.
Top 10 Frequently asked SQL Query Interview Questions

Earlier articles on Interview Questions and Answers frequently asked on MVC and OOPS as below:

SQL Query Interview Questions and Answers

• How to find second highest salary of Employee by SQL?
Second highest salary of an employee can be found in many ways, one can use either SQL Join or Sub-query in order to solve this problem.
select MAX(Salary) FROM tblEmployee WHERE Salary NOT IN (select MAX(Salary) from tblEmployee);

• How to find maximum salary from each office by SQL query?

One can find the maximum salary for every office by gathering all records by DepartmentID and afterward utilizing MAX() function to compute greatest salary in each group or each office.
SELECT DeptID, MAX(Salary) FROM tblEmployee GROUP BY DeparmentID.

• Compose SQL Query to show the present date.

SQL has inbuilt function called GetDate() which returns the current timestamp. This will work in Microsoft SQL Server, different sellers like Oracle and MySQL also has comparable capacities.
SELECT GetDate(); 

• Compose a SQL Query to check whether date is of given format or not.

SQL has IsDate() function which is utilised to check passed value is a date or not of determined arrangement, it returns 1(true) or 0(false) in like manner.
SELECT  ISDATE('09/09/2017') AS "MM/DD/YYYY";

• Compose a SQL Query to print the name of the employee whose DOB is between 09/09/2016 to 09/09/2017.

This SQL question is precarious, however you can use BETWEEN condition to get all records whose date fall between two dates.
SELECT DISTINCT EmployeeName FROM tblEmployees WHERE DOB  BETWEEN ‘09/09/2016’ AND ‘09/09/2017’;

• Compose a SQL query to seek out names of employee begin with ‘T’ .

-- this will search only employee name starts from character 'T'
SELECT * FROM EmployeeName WHERE EmployeeName like 'T%';
-- OR you can also write a query to find all EmployeeName those who have character 'T' 
SELECT * FROM EmployeeName WHERE EmployeeName like '%T%';

• What is SQL Server Agent?

SQL Server agent plays a vital role within the every day tasks of a info administrator (DBA). Its purpose is to ease the implementation of tasks for the DBA, with its full-perform planning engine, that permits you to schedule your own jobs and scripts.

What is Trigger?

Trigger permits us to execute a batch of SQL code once AN insert, update or delete command is dead against a selected table. Triggers square measure special varieties of keep procedures that square measure outlined to execute mechanically in situation of or once knowledge modifications. They will be dead mechanically on the insert, delete and update operation.

• What is a Temporary table in SQL Server?

More or less, a temp table is a transitory storage structure. It implies you can utilise a temp table to store information incidentally so you can control and change it before it achieves its destination format.

• Types of Temporary Tables?

  • Local Temp Table
  • Global Temp Table
Local temporary tables can be available to current user connection and they are automatically deleted once the user connection discontinue from database. Local temp tables are used with (#) sign.
Global Temporary tables are like permanent tables in database and it is available to any user by any connection and it can be deleted only when all connections are close.

Conclusion

Despite the fact that requesting that hopefuls compose SQL query is a superior approach to check one's SQL abilities, some of the time it likewise pays to make theoretical inquiries just to check whether knows about fundamental ideas or not, especially amid telephone interviews.

Relevant Reading