Blog Archives

SQL Tricky Interview Questions Preparation Course

This course contains tricky and nasty SQL interview questions that an interviewer asks. It is a compilation of advanced SQL interview questions after attending dozens of technical interviews in top-notch companies like- Oracle, Google, Ebay, Amazon etc. Each question is

Posted in SQL, SQL Interview Questions

Write a SQL query to maximum Zipcode from a table without using MAX or MIN aggregate functions.

Consider Zipcode_list table with column Zipcode ZIPCODE 7500 7525 7550 7600 7575 Answer: Point to be noted is that the Maximum zipcode is not smaller than any Zipcode in the list. We can use self join to find the list

Posted in SQL, SQL Interview Questions

Given a list of student names and grade. Write a query to print a comma separated list of student names in a grade.

Students Grade | Name 1 | John 1 | George 1 | Jane 2 | Smith 2 | Anne 2 | Scott 3 | Larry 3 | Bill Answer: We can use LISTAGG function in Oracle for this purpose. It

Posted in SQL, SQL Interview Questions

What is the difference between Correlated and Un-correlated Sub query?

When we write a subquery in such a way that inner subquery and outer main query are interdependent, then we call it s correlated Sub query. In this case, for executing every row of inner query, the outer query is

Posted in SQL, SQL Interview Questions

Given an Employee table with Manager_ID as column, print First name, Manager ID and Level of employees in Organization Structure?

Answer: In Oracle, we can CONNECT BY clause for this. The starting point will be the employee who does not have a manager. Below that we can connect the employee IDs with their Manager IDs and keep printing the records.

Posted in SQL, SQL Interview Questions

Write a query to create an empty table from an existing table?

Answer: An empty table is a table with same structure as the given table. But it does not contain records. To create an empty table, we have to run a SELECT query so that no records are returned. But we

Posted in SQL, SQL Interview Questions

Write SQL Query to get the list of grades with total score more than average score.

Consider Student and Grade tables Student: ID, name, grade_ID, score Grade: ID, grade_num Answer: We can use WITH clause to get the total score in each grade. We can also use WITH clause to get the average score among all

Posted in SQL, SQL Interview Questions

What are the differences between CASE and DECODE in SQL?

Main differences between Case and Decode statements are: Easier to Read: CASE is more flexible and easier to read than DECODE. ANSI Compatible: CASE is an ANSI standard. But DECODE is internal to Oracle. Location: DECODE is used only inside

Posted in SQL, SQL Interview Questions

Write a Query to get Unique names of products without using DISTINCT keyword.

We can use GROUP BY for this purpose. It can print the distinct groups of PRODUCT NAME. SELECT prod_name FROM product GROUP BY prod_name

Posted in SQL, SQL Interview Questions

What is the use of WITH clause in SQL?

In SQL, WITH clause is used to create a Subquery or View for a set of data. The main uses of WITH clause are: Simplify: It can simplify a SQL query by creating a subset of data. Reduce Repetition: WITH

Posted in SQL, SQL Interview Questions