SQL Interview Questions - Tutorialspoint
SQL Interview Questions - Tutorialspoint
SQL Interview Questions - Tutorialspoint
Dear readers, these SQL Interview Questions have been designed specially to get you
acquainted with the nature of questions you may encounter during your interview for the subject of
SQL. As per my experience good interviewers hardly plan to ask any particular question during
your interview, normally questions start with some basic concept of the subject and later they
continue based on further discussion and what you answer:
SQL or Structured Query Language is a language; language that communicates with a relational
database thus providing ways of manipulating and creating databases. MySQL and Microsoft’s
SQL Server both are relational database management systems that use SQL as their standard
relational database language.
PL/SQL is a dialect of SQL that adds procedural features of programming languages in SQL. It was
developed by Oracle Corporation in the early 90's to enhance the capabilities of SQL.
What are various DDL commands in SQL? Give brief description of their
purposes.
What are various DML commands in SQL? Give brief description of their
purposes.
What are various DCL commands in SQL? Give brief description of their
purposes.
Is a NULL value same as zero or a blank space? If not then what is the
difference?
A NULL value is not same as zero or a blank space. A NULL value is a value which is ‘unavailable,
unassigned, unknown or not applicable’. Whereas, zero is a number and blank space is a
character.
True.
If a table contains duplicate rows, does a query result display the duplicate
values by default? How can you eliminate duplicate rows from a query
result?
A query result displays all rows including the duplicate rows. To eliminate duplicate rows in the
result, the DISTINCT keyword is used in the SELECT clause.
The BETWEEN operator displays rows based on a range of values. The IN condition operator
checks for values contained in a specific set of values.
How do you search for a value in a database table when you don’t have the
exact value to search for?
https://www.tutorialspoint.com/sql/sql_interview_questions.htm 2/9
2/24/2021 SQL Interview Questions - Tutorialspoint
In such cases, the LIKE condition operator is used to select rows that match a character pattern.
This is also called ‘wildcard’ search.
What is the default ordering of data using the ORDER BY clause? How
could it be changed?
The default sorting order is ascending. It can be changed using the DESC keyword, after the
column name in the ORDER BY clause.
What is the difference between the NVL and the NVL2 functions?
The NVL(exp1, exp2) function converts the source expression (or value) exp1 to the target
expression (or value) exp2, if exp1 contains NULL. The return value has the same data type as that
of exp1.
The NVL2(exp1, exp2, exp3) function checks the first expression exp1, if it is not null then, the
second expression exp2 is returned. If the first expression exp1 is null, then the third expression
exp3 is returned.
The NULLIF function compares two expressions. If they are equal, the function returns null. If they
are not equal, the first expression is returned.
There are two ways to implement conditional processing or IF-THEN-ELSE logic in a SQL
statement.
Using CASE expression
Using the DECODE function
You want to display a result query from joining two tables with 20 and 10
rows respectively. Erroneously you forget to write the WHERE clause. What
would be the result?
The result would be the Cartesian product of two tables with 20 x 10 = 200 rows.
The cross join produces the cross product or Cartesian product of two tables. The natural join is
based on all the columns having same name and data types in both the tables.
What is the purpose of the group functions in SQL? Give some examples of
group functions.
Group functions in SQL work on sets of rows and returns one result per group. Examples of group
functions are AVG, COUNT, MAX, MIN, STDDEV, SUM, VARIANCE.
By default, group functions consider all values including the duplicate values.
True.
True.
It doesn’t have a GROUP BY clause. The subject_code should be in the GROUP BY clause.
The WHERE clause cannot be used to restrict groups. The HAVING clause should be used.
https://www.tutorialspoint.com/sql/sql_interview_questions.htm 5/9
2/24/2021 SQL Interview Questions - Tutorialspoint
False. A single row subquery returns only one row from the inner SELECT statement.
True.
True.
https://www.tutorialspoint.com/sql/sql_interview_questions.htm 6/9
2/24/2021 SQL Interview Questions - Tutorialspoint
The DML statements are used to add new rows to a table, update or modify data in existing rows,
or remove existing rows from a table.
True.
Null values can be inserted into a table by one of the following ways −
Implicitly by omitting the column from the column list.
Explicitly by specifying the NULL keyword in the VALUES clause.
False. INSERT statement allows to add rows to a table copying rows from an existing table.
The INSERT statement can be used to add rows to a table by copying from another table. In this
case, a subquery is used in the place of the VALUES clause.
What happens if you omit the WHERE clause in the UPDATE statement?
https://www.tutorialspoint.com/sql/sql_interview_questions.htm 7/9
2/24/2021 SQL Interview Questions - Tutorialspoint
Can you modify the rows in a table based on values from another table?
Explain.
Yes. Use of subqueries in UPDATE statements allow you to update rows in a table based on values
from another table.
False. The DELETE statement is used for removing existing rows from a table.
Can you remove rows from a table based on values from another table?
Explain.
Yes, subqueries can be used to remove rows from a table based on values from another table.
True.
True.
The MERGE statement allows conditional update or insertion of data into a database table. It
performs an UPDATE if the rows exists, or an INSERT if the row does not exist.
https://www.tutorialspoint.com/sql/sql_interview_questions.htm 8/9
2/24/2021 SQL Interview Questions - Tutorialspoint
True.
VARCHAR2 represents variable length character data, whereas CHAR represents fixed length
character data.
True.
What is Next ?
Further you can go through your past assignments you have done with the subject and make sure
you are able to speak confidently on them. If you are fresher then interviewer does not expect you
will answer very complex questions, rather you have to make your basics concepts very strong.
Second it really doesn't matter much if you could not answer few questions but it matters that
whatever you answered, you must have answered with confidence. So just feel confident during
your interview. We at tutorialspoint wish you best luck to have a good interviewer and all the very
best for your future endeavor. Cheers :-)
https://www.tutorialspoint.com/sql/sql_interview_questions.htm 9/9