TOP SQL Interview Questions and Answers

Q1 - What are UNION, MINUS, and INTERSECT commands?

If there are two queries Q1 and Q2, The UNION operator is used to combine the results of two tables while also removing duplicate entries. The MINUS operator is used to return rows from the first query but not from the second query. The INTERSECT operator is used to combine the common results of both queries.

Q2 - What are Tables and Fields?

A table is basically a collection of data components organized in rows and columns in a relational database. A table can also be thought of as a useful representation of relationships. The most basic form of data storage is the table. Fields are columns in the table.

Q3 - What is a Self-Join?

A self-join is one type of join that can be used to connect two tables. As a result, it is a unary relationship. Each row of the table is attached to itself and all other rows of the same table are in self-join. As a result, a self-join is mostly used to combine and compare rows from the same database table.

Q4 - How to remove duplicate rows in SQL?

DELETE FROM table WHERE ID IN (
SELECT
ID, COUNT(ID)
FROM table
GROUP BY ID
HAVING
COUNT (ID) > 1);

Q5 - What are the Constraints in SQL?

These are used to specify the limit on the data type of the table. Below are some examples of constraints that can be used

  • NOT NULL
  • CHECK
  • DEFAULT
  • UNIQUE
  • PRIMARY KEY
  • FOREIGN KEY

Q6 - What are the syntax and use of the COALESCE function?

COALESCE function returns the first non-NULL value from a series of expressions, It is very useful in finding meaningful value in some queries. Syntax of function - COALESCE (exp1, exp2, ….)

Launch your GraphyLaunch your Graphy
100K+ creators trust Graphy to teach online
𝕏
Unfold Data Science 2024 Privacy policy Terms of use Contact us Refund policy