Prepare Interview

Mock Exams

Make Homepage

Bookmark this page

Subscribe Email Address

SQL Query Interview Questions and Answers

Ques 51. Explain the purpose of the SQL GROUP_CONCAT() function.

The GROUP_CONCAT() function is used to concatenate values from multiple rows into a single string, grouped by a specified column.

Example:

SELECT department, GROUP_CONCAT(employee_name) FROM Employee GROUP BY department;

Is it helpful? Add Comment View Comments
 

Ques 52. What is a common use case for the SQL COALESCE() function?

The COALESCE() function is used to return the first non-null expression among its arguments. A common use case is handling null values in a query.

Example:

SELECT COALESCE(column1, 'DefaultValue') FROM table;

Is it helpful? Add Comment View Comments
 

Ques 53. Explain the purpose of the SQL ROLLUP operator.

The ROLLUP operator is used in conjunction with the GROUP BY clause to generate subtotals and grand totals for a set of columns in the result set.

Example:

SELECT department, city, SUM(salary) FROM Employee GROUP BY ROLLUP (department, city);

Is it helpful? Add Comment View Comments
 

Ques 54. Write a SQL query to find the nth highest salary without using the LIMIT clause.

SELECT salary FROM Employee e1 WHERE n-1 = (SELECT COUNT(DISTINCT salary) FROM Employee e2 WHERE e1.salary <= e2.salary);

Is it helpful? Add Comment View Comments
 

Ques 55. Explain the purpose of the SQL LEAD() and LAG() functions.

The LEAD() function is used to access the next row's data in the result set, while the LAG() function is used to access the previous row's data.

Example:

SELECT employee_name, salary, LEAD(salary) OVER (ORDER BY salary) AS NextSalary FROM Employee;

Is it helpful? Add Comment View Comments
 

Most helpful rated by users:

©2025 WithoutBook