12 Essential SQL Interview Questions and Answers - Upwork™
12 Essential SQL Interview Questions and Answers - Upwork™
12 SQL interview
questions and answers
Looking for SQL freelancers to build your team?
Check out Upwork's top SQL Programmers (https://www.upwork.com/hire/sql-
programmers/)
A A RDBMS is a system that organizes data into tables called relations, which are
further organized into columns (fields) and rows (often called tuples). The
relational model allows data to be queried in a nearly unlimited number of ways,
making it great for sorting through large volumes of data. It’s important to pick a
SQL developer who’s experienced with the particular set of web technologies
you plan to use to support your app. Common SQL dialects include PL/SQL for
Oracle, T-SQL for MS SQL, and JET SQL for MS Access. Look up any particular
dialects used for your chosen RDBMS.
Q What are the standard SQL commands every SQL developer should
know?
A The basic SQL commands can be organized into the following categories:
https://www.upwork.com/i/interview-questions/sql/ 1/16
6/4/2018 12 Essential SQL interview questions and answers - Upwork™
Q Can you explain how a RDBMS organizes data into tables and fields?
https://www.upwork.com/i/interview-questions/sql/ 2/16
6/4/2018 12 Essential SQL interview questions and answers - Upwork™
Q What is a NULL value and how does it differ from a zero value?
A The easiest way to explain this difference is to recognize that zero is a value
representing the number zero. NULL is a non-value or a placeholder for data that
is not currently known or specified. The result of any operation on a NULL value,
as in arithmetic, will be undefined.
A Constraints are rules you can place on columns or tables to limit the type of data
that can be entered into a table. This prevents errors and can improve the
accuracy and reliability of the database as a whole. Common constraints include:
https://www.upwork.com/i/interview-questions/sql/ 3/16
6/4/2018 12 Essential SQL interview questions and answers - Upwork™
User-Defined Integrity: Enforces rules set by the user that do not fall into
the other categories.
https://www.upwork.com/i/interview-questions/sql/ 4/16
6/4/2018 12 Essential SQL interview questions and answers - Upwork™
Q Explain the difference between an inner join and outer join using an
example.
A An inner join is when you combine rows from two tables and create a result set
based on the predicate, or joining condition. The inner join only returns rows
when it finds a match in both tables. An outer join will also return unmatched
rows from one table if it is a single outer join, or both tables if it is a full outer
join. A solid example of this will clearly illustrate the difference and demonstrate
how well the developer understands joins.
A The issue here is that there must be a GROUP BY clause here. This query will get
the average order amount by customer (UserId) where the customer has at least
1 order. The correct query is listed below:
Q Consider the two tables below. Write a query that retrieves all
employees recruited by John Do. How would you write a second query
to retrieve all employees that were not recruited by any recruiter?
Employee Table
Id Name RecruitedBy
https://www.upwork.com/i/interview-questions/sql/ 5/16
6/4/2018 12 Essential SQL interview questions and answers - Upwork™
2 Paul Smith 1
3 John Do NULL
4 Alex Lee 3
5 Lisa Kim 3
Recruiter Table
Id Name
1 Bob Smith
2 Paul Allen
3 John Do
A The following query will retrieve all recruiters recruited by John Do.
SELECT Employee.
To retrieve all employees who were not recruited by anyone in the recruiter table,
you could use the following query:
Q Write a SQL query to find the 10th tallest peak (“Elevation”) from a
“Mountain” table. Assume that there are at least 10 records in the
Mountain table. Explain your answer.
https://www.upwork.com/i/interview-questions/sql/ 6/16
6/4/2018 12 Essential SQL interview questions and answers - Upwork™
The first query takes the top 10 mountains by elevation in the table and lists them
in descending order, with the tallest mountain at the top of the list. However,
since we want the 10th tallest mountain, the second query, “ AS Mount ORDER
BY Elevation”, promptly reorders the list of 10 in ascending order before the top
record is selected. Note that not all databases support the “TOP” keyword, so
answers may vary. Another possible solution that follows a similar logic for
MySQL or PostreSQL is detailed below, this time using the “LIMIT” keyword.
Q Given two tables created in the code block below, how would you write
a query to fetch values in table “fibonacci” that are not in table “prime”
without using the “NOT” keyword? Can you name a database
technology where this is not possible?
A SQLite, PostgreSQL, and SQL Server all support the ever useful “except” keyword
which can be employed as detailed below
https://www.upwork.com/i/interview-questions/sql/ 7/16
6/4/2018 12 Essential SQL interview questions and answers - Upwork™
A popular database technology that does not support “except” is MySQL, which
is why it must use the “not in” keyword. Note that for Oracle, the “minus”
keyword must be used instead.
Question
Question
Answer
Answer
Submit
https://www.upwork.com/i/interview-questions/sql/ 8/16
6/4/2018 12 Essential SQL interview questions and answers - Upwork™
(/o/profiles/users/_~017b90cdc12bedc13a/)
NELSON T.
(/o/profiles/users/_~017b90cdc12bedc13a/)
Web Developer
https://www.upwork.com/i/interview-questions/sql/ 9/16
6/4/2018 12 Essential SQL interview questions and answers - Upwork™
(/o/profiles/users/_~017627e62d8941926c/)
OSSIAN R.
(/o/profiles/users/_~017627e62d8941926c/)
Software Consultant
(/o/profiles/users/_~017281654cd8dcb2ee/)
SANJA K.
(/o/profiles/users/_~017281654cd8dcb2ee/)
Email Marketing Expert & IT Consultant
https://www.upwork.com/i/interview-questions/sql/ 10/16
6/4/2018 12 Essential SQL interview questions and answers - Upwork™
(/o/profiles/users/_~013bcc7a64dde8167d/)
BILAL S.
(/o/profiles/users/_~013bcc7a64dde8167d/)
expert web developer/PHP/wordpress/HTML/CSS
(/o/profiles/users/_~014f37d91cb11de207/)
ALEKSANDAR I.
(/o/profiles/users/_~014f37d91cb11de207/)
Senior C# .Net Desktop Developer
https://www.upwork.com/i/interview-questions/sql/ 11/16
6/4/2018 12 Essential SQL interview questions and answers - Upwork™
(/o/profiles/users/_~01cab2b31542a48296/)
SAQIB Z.
(/o/profiles/users/_~01cab2b31542a48296/)
Full Stack Web Developer | Software Engineer
(/o/profiles/users/_~016974c25bd11d07f1/)
MOHSIN Z.
(/o/profiles/users/_~016974c25bd11d07f1/)
Microsoft Database Engineer (Access/SQL)
https://www.upwork.com/i/interview-questions/sql/ 12/16
6/4/2018 12 Essential SQL interview questions and answers - Upwork™
(/o/profiles/users/_~01098641b6ad2a5cc0/)
ALEXANDER S.
(/o/profiles/users/_~01098641b6ad2a5cc0/)
Full stack web-developer
https://www.upwork.com/i/interview-questions/sql/ 13/16
6/4/2018 12 Essential SQL interview questions and answers - Upwork™
Top-skilled freelancers and the essentials to find and work with them.
https://www.upwork.com/i/interview-questions/sql/ 14/16
6/4/2018 12 Essential SQL interview questions and answers - Upwork™
COMPANY
About Us (/about/)
Contact (https://support.upwork.com/hc/en-us)
Careers (/about/careers/)
Press (/press/)
RESOURCES
BROWSE
Freelancers in UK (/local/united-kingdom/)
https://www.upwork.com/i/interview-questions/sql/ 15/16
6/4/2018 12 Essential SQL interview questions and answers - Upwork™
FOLLOW US
(https://plus.google.com/107040851368295259701)
(https://www.facebook.com/upwork)
(https://www.linkedin.com/company/upwork)
(https://twitter.com/Upwork)
(https://www.youtube.com/channel/UCvxGFOnwUBDHHcxuPqhe4CQ)
(https://www.instagram.com/upworkinc/)
MOBILE APP
(https://itunes.apple.com/us/app/upwork-
messenger/id944344799?
(https://play.google.com/store/apps/details?
mt=8)id=com.upwork.android&hl=en)
https://www.upwork.com/i/interview-questions/sql/ 16/16