Home / Interview / SQL :: General Questions

Interview :: SQL

31) What is the difference between SQL and PL/SQL?

SQL or Structured Query Language is a language which is used to communicate with a relational database. It provides a way to manipulate and create databases. On the other hand, PL/SQL is a dialect of SQL which is used to enhance the capabilities of SQL. It was developed by Oracle Corporation in the early 90's. It adds procedural features of programming languages in SQL.

In SQL single query is being executed at once whereas in PL/SQL a whole block of code is executed at once.

SQL is like the source of data that we need to display on the other hand PL/SQL provides a platform where the SQL the SQL data will be shown.

SQL statement can be embedded in PL/SQL, but PL/SQL statement cannot be embedded in SQL as SQL do not support any programming language and keywords.

32) Is it possible to sort a column using a column alias?

Yes. You can use the column alias in the ORDER BY instead of WHERE clause for sorting.

33) What is the difference between clustered and non-clustered index in SQL?

There are mainly two type of indexes in SQL, Clustered index and non clustered index. The differences between these two indexes is very important from SQL performance perspective.

  1. One table can have only one clustered index, but it can have many non-clustered index. (Approximately 250).
  2. A clustered index determines how data is stored physically in the table. Clustered index stores data in the cluster, related data is stored together, so that retrieval of data becomes simple.
  3. Clustered indexes store the data information and the data itself whereas non-clustered index stores only the information, and then it will refer you to the data stored in clustered data.
  4. Reading from a clustered index is much faster than reading from non-clustered index from the same table.
  5. Clustered index sort and store data row in the table or view based on their key value, while non-cluster has a structure separate from the data row.
34) What is the SQL query to display the current date?

There is a built-in function in SQL called GetDate() which is used to return the current timestamp.

35) Which are the most commonly used SQL joins?

Most commonly used SQL joins are INNER JOIN and LEFT OUTER JOIN and RIGHT OUTER JOIN.

36) What are the different types of joins in SQL?

Joins are used to merge two tables or retrieve data from tables. It depends on the relationship between tables.

Following are the most commonly used joins in SQL:

Inner Join: inner joins are of three type:

  1. Theta join
  2. Natural join
  3. Equijoin

Outer Join: outer joins are of three type:

  1. right outer join
  2. Left outer join
  3. Full outer join
37) What is Inner Join in SQL?

Inner join:

Inner join returns rows when there is at least one match of rows between the tables. INNER JOIN keyword joins the matching records from two tables.

SQL Interview Questions

INNER JOIN

38) What is Right Join in SQL?

Right Join:

Right Join is used to retrieve rows which are common between the tables and all rows of a Right-hand side table. It returns all the rows from the right-hand side table even though there are no matches in the left-hand side table.

SQL Interview Questions

RIGHT JOIN

39) What is Left Join in SQL?

Left Join:

The left join is used to retrieve rows which are common between the tables and all rows of the Left-hand side table. It returns all the rows from the Left-hand side table even though there are no matches on the Right-hand side table.

SQL Interview Questions

LEFT JOIN

40) What is Full Join in SQL?

Full Join:

Full join return rows when there are matching rows in any one of the tables. This means it returns all the rows from the left-hand side table and all the rows from the right-hand side table.

SQL Interview Questions

FULL OUTER JOIN