Must Know SQL Questions for Your Upcoming Interviews

1.Find the second high salary employee from Employee table consist of EmpID, Name,Salary Columns.
Select TOP 1 * from
(
Select TOP 2 * from Emp.Employee
Order by Salary desc
) as A
Order by Salary asc

2.Find the nTh Salary Employee.
Select TOP 1 * from
(
Select TOP N * from Emp.Employee
Order by Salary desc
) as A
Order by Salary asc

3.How to display current date and time
Select CURRENT_TIMESTAMP as CurrentDateTime

4.How to get the Todays Date in SQL Server
Select GETDATE() as TodaysDateTime

5.How to sum two numbers in SQL (10+2)
Select (10+2) as SumofNum

6.What are SQL Expressions?
An SQL Expression is a combination of one or more values, operators, and SQL functions that evaluate to a value.

7.What is OLTP?
OLTP stands for ‘Online Transactional Processing’. It refers to the management of transactional data using computer systems.

8.What is OLAP?
OLAP stands for ‘Online Analytical Processing’. It is a technology that organizes large business databases and supports complex analysis without negatively affecting transactional systems.
Example of OLAP:
Netflix, Spotify

9.Give examples of OLTP.
Banking, Online booking

10.What is the default ordering in SQL Server?
The default order in SQL Server is ascending order.

11.What is the ORDER BY clause?
The ORDER BY command is used to sort the result set in ascending or descending order.

12.How to perform sorting on data in SQL Server.
Use the ORDER BY clause to sort the data.

13.How to get the Top 5 records in SQL
Select TOP 5 * from dbo.Employee

14.How to fetch 20 % percent of records in SQL Server
Select TOP 20 percent * from dbo.Employee

15.What is the use of the COALESCE function?
The COALESCE function evaluates a set or list of input parameters sequentially and returns the first non-null value among them.

16.How to write COALESCE Function
Select (FirstName, MiddleName), LastName from dbo.Employee

17.What is null value?
NULL means the absence of any value.

18.How to check null values in a column.
Using the ‘IS NULL’ function.
Select * from dbo.Employee
Where MiddleName is null

19.How to count number of rows in a table
Select Count(*) from dbo.Employee

20.How to find alternate records in a table
Select * from dbo.Employee
Where EmployeeKey%2 = 0

Leave a Reply

Your email address will not be published. Required fields are marked *