0% found this document useful (0 votes)
9 views1 page

Crack The Top 40 SQL Interview Questions by The Educative Team Jun, 2022 Grokking The Tech Interview

The document emphasizes the importance of SQL (Structured Query Language) for careers in data science and analysis, highlighting its ease of learning and high demand in various business fields. It outlines key areas of knowledge for SQL interviews, including basic SQL concepts, joins, and stored procedures, and provides a list of 40 essential SQL interview questions. Additionally, it discusses the relationship between SQL and relational database management systems, as well as various SQL commands and functions.

Uploaded by

8j84smx4mm
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views1 page

Crack The Top 40 SQL Interview Questions by The Educative Team Jun, 2022 Grokking The Tech Interview

The document emphasizes the importance of SQL (Structured Query Language) for careers in data science and analysis, highlighting its ease of learning and high demand in various business fields. It outlines key areas of knowledge for SQL interviews, including basic SQL concepts, joins, and stored procedures, and provides a list of 40 essential SQL interview questions. Additionally, it discusses the relationship between SQL and relational database management systems, as well as various SQL commands and functions.

Uploaded by

8j84smx4mm
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

>'%B+=1%K15")B%8'*=L%81%3'#%)21*%5+&+7

:1&%2&+*&15
J01$%"$%+00
M(%)2"$#%K15")BL%(')%+#*11%&'%')*
;*"@+,(%;'3",(L%"$,3)5"$#%,''="1%0'3",(7

!"#$%"$%&'%(')*%+,,')$&%-!"##$%##&'().
/'*%(')*%01*2'$+3"415%1601*"1$,17

!"#$%"$%8"&9%:''#31

Not you? Sign in or create an account

;)<3"2915%"$ :*'=="$#%&91%>1,9%?$&1*@"18

>91%A5),+&"@1%>1+B C'33'8

D)$%EF G EH%B"$%*1+5 G I"2&1$

!+@1

*+,'-./01./(2.34.567
89/1+:81;.<=1!/8(9!

If you’re seeking a career in data science,


data analysis, or plan on working with
databases at all, consider adding SQL
(Structured Query Language) to your
skillset. It’s straightforward, easy to learn,
and individuals with SQL experience are
in high demand.

One of the reasons there’s such a strong


demand for SQL skills is the widespread
use of databases in virtually every field
of business. Databases can process much
more data than traditional spreadsheets
like Microsoft Excel, and SQL is used to
access and extract that data within
relational databases. As a result, relational
database management systems (RDBMS)
like Microsoft SQL Server, MySQL, and
Oracle are the most popular database
systems currently in use.

Furthermore, SQL is frequently used


alongside more powerful programming
languages like Python or Java to analyze
and manipulate data. Having SQL in your
repertoire is a great way to increase your
versatility and utility as a developer.

Check out An Introductory Guide to SQL if


you’d like to become better acquainted
with the fundamental concepts of SQL.

Let’s get started!

We’ll cover:

Overview of the SQL interview

Top 40 SQL interview questions

Wrap up and additional resources

>:1+:81;.(?./01.567.89/1+:81;
Due to the diverse applicability of SQL,
there is a wide range of positions that
could require you to demonstrate your
knowledge of SQL, and the interview
process will differ from role to role.

In general, you can prepare by practicing


writing error-free SQL queries and
familiarizing yourself with the concepts
that require a particular command.
Interviewers are looking for candidates
who are comfortable discussing the
strengths and weaknesses of different SQL
methods, understand how databases
process indexes, joins, views, and can
correctly identify optimal solutions for a
variety of situations. The more you
practice, the easier it will be to confidently
tackle more complex SQL problems.

An Introductory Guide to SQL goes over


eight key areas of knowledge that
frequently come up during SQL
interviews:

Basic SQL

Joins

Nested Queries

Multi-Table Operations

Views

Stored Procedures

Triggers

Miscellaneous (e.g., triggers,


foreign keys, etc.)

Remember to take some time to reflect on


what you’re learning and see if you can
connect your technical knowledge to
other experiences. It’s great to hone your
skills using technical challenges, but we
also recommend sharpening your
behavioral interviewing skills.

Check out:
Grokking the Behavioral Interview

@(2.34.567.89/1+:81;.<=1!/8(9!
This section will cover 40 SQL questions
that you should know before heading into
an interview and should provide a general
idea of the kind of questions to expect.

A&.B0,/.8!.567C
SQL is a non-procedural programming
language developed by IBM in the 1970s
and then later by Oracle. SQL is used by
almost all relational databases to write
queries, access, edit, and retrieve data.

D&.B0,/.8!.,.E,/,F,!1C
A database is an organized collection of
digital information, or data, stored in a
computer system. Unlike spreadsheets, a
database can handle massive quantities of
information while allowing multiple users
access to the same database to run secure
and independent queries.

G&.B0,/.8!.,9.HIJK5L.,9E.0(;.8!.8/
E8??1+19/.?+().,./+,E8/8(9,M.IJK5C
An RDBMS or Relational Database
Management System is essentially a
database utilizing a tabular schema to
organize multiple data elements related to
each other. An RDBMS lets your define,
create, and maintain relational databases
in addition to providing controlled access
to the data within.
A DBMS or Database Management System
functions similarly to the RDBMS
described above. However, DBMS data
elements are stored as files rather than in
tabular form, and there is no relationship
between different data elements.

Related article: What is a relational


database? A deep dive

3&.NO2M,89./01.E8??1+19/./"21!.(?
567.'()),9E!&
There are six basic types of SQL
commands.

P&.B0,/.8!./01.E8??1+19'1.F1/;119
567.,9E.K"567C
SQL is a programming language, while
MySQL is a popular, open-source RDBMS.
MySQL is used to store and organize data,
while SQL is used to access, edit, update
and maintain data in MySQL.

Related article: MySQL tutorial: The


beginner’s guide to using MySQL

Q&.B0,/.8!.,. PRIMARY KEY .'(9!/+,89/C

A PRIMARY KEY constraint is a column (or


combination of columns) used to
designate each table row with a unique
identifier. You can think of a primary key
as having a similar function to national
government-issued identification
numbers, a citizen's Social Security
Number, or a vehicle identification
number (VIN).

Note: There’s a limit of one PRIMARY KEY

constraint per table. All columns defined


within a PRIMARY KEY constraint must be
defined as NOT NULL .

R&.B0,/.8!.,. FOREIGN KEY .'(9!/+,89/C

A FOREIGN KEY is a column or collection of


fields in a table referencing a PRIMARY KEY

in another table. The table containing the


primary key is known as the parent table,
and the table containing the foreign key is
called the child table.

For example, the PRIMARY KEY in the


parent table below is OwnerID . The

PRIMARY KEY uniquely identifies


individual pet owners.

For this child table, the PRIMARY KEY is


PetID , and the OwnerID column is a
FOREIGN KEY because it references the
primary key of another table.

S&.B0,/.8!.,. UNIQUE .'(9!/+,89/C


Like the PRIMARY KEY , the UNIQUE

constraint also ensures that each value is


different from the others in its column.
However, tables can have multiple
columns with UNIQUE constraints, unlike
the PRIMARY KEY constraint, limited to just
one.

T&.B0,/.,+1.567.U(89!C.B0,/.,+1./01
E8??1+19/./"21!.(?.U(89!C
In SQL, a JOIN clause combines rows of
data in different tables with a shared
column. You can SELECT and return
records with matching values in both
tables based on this relationship.

There are four kinds of JOIN clauses in


SQL:

Related article: What are SQL joins?


Types of SQL joins explained

A4&.B0,/.8!.,.!1M?VU(89C
A JOIN clause combines rows from two or
more tables based on a related column
between them. A self-join is a regular join,
but the table is joined with itself – this is
extremely useful for comparisons within a
table.

Joining a table with itself means that each


table row is combined with itself and with
every other row of the table.

AA&.B0,/.8!.,.'+(!!.U(89.W*,+/1!8,9
U(89XC
In SQL, the cross join combines each row
of the first table with each row of the
second table. It is also known as the
Cartesian join since it returns the
Cartesian product of the sets of rows from
the joined tables.

AD&.B0,/Y!./01.E8??1+19'1.F1/;119.,
WHERE .'M,=!1.,9E.,. HAVING .'M,=!1C

The WHERE clause can be used to establish


the first condition that groups and returns
only the rows that meet that condition
into a result set. Then, secondary
conditions can be applied using the
HAVING clause to return only the groups
within that set that meet your new
criteria.

AG&.B0,/Y!./01.E8??1+19'1.F1/;119.,
TRUNCATE .'()),9E.,9E.,. DELETE
'()),9EC

The TRUNCATE command is faster than


DELETE , but unlike the DELETE command,
data cannot be rolled back after using it to
recover data that has been mistakenly
deleted.

A3&.B0,/.8!.,.<=1+"C
In the context of this article, a query is a
set of instructions written in a query
language like SQL that allows an
individual to access information held in a
database.

AP&.B0,/.8!.,.!=F<=1+"C
A subquery or nested query is a query
within a query.

There are two types of subqueries:


Correlated and Non-correlated.

Correlated subqueries refer to a


column in a table specified by the
FROM keyword of the main query.

Non-correlated subqueries are


independent and their output is
substituted in the main query.

AQ&.B0,/.,+1. UNION L. UNION ALL L


MINUS L.,9E. INTERSECT .!1/
(21+,/(+!C
The UNION operation combines the results
of two or more SELECT statements. For
example, getting the UNION of sets A and
B, this operation would return all rows
from both sets, excluding any duplicate
rows.

The UNION ALL operation does the same


thing as UNION , but includes duplicate

rows in its result set.

The INTERSECT operation combines the


results of two SELECT statements but only
returns the rows with matching values in
both sets.

The MINUS operation combines the results


of two SELECT statements but only returns
rows with values that belong to the first
set of the result.

AR&.B0,/.,+1.Z(+),M8[,/8(9.,9E
I19(+),M8[,/8(9C
Normalization refers to the methods used
to remove redundancies and
inconsistencies in a database.

Denormalization refers to methods used


to improve the performance of queries.

Normalization introduces more tables to a


database, whereas Denormalization
reduces the number of tables.

AS&.B0,/.,+1.!',M,+.?=9'/8(9!C
Scalar functions are defined by the user
and return a single value (i.e., int, char,
float, etc.) based on the input value.

Common SQL scalar functions:

CONCAT() concatenates two or more


character strings.

FORMAT() sets the format to display a


collection of values.

LEN() calculates the total length of a


given column.

MID() extracts substrings from a


collection of string values.

ROUND() rounds the integer value for a


numeric field.

NOW() returns the current date and


time.

RAND() calculates a random collection


of numbers of a given length.

AT&.B0,/.,+1.,%%+1%,/1.?=9'/8(9!C
In SQL, aggregate functions (also known
as group functions) are applied to a group
of values (or all values) to calculate and
return a single value.

Common SQL aggregate functions:

AVG calculates the average or mean of


all values in a group.

COUNT calculates the number of rows


in group, including rows with NULL

values.

MIN and MAX returns the smallest and


largest value in a group, respectively.

SUM returns the sum of all non- NULL


values in a group.

STDDEV calculates the standard


deviation.

VARIANCE calculates the variance.

D4&.B0,/.8!.,.!/(+1E.2+('1E=+1C
Instead of writing the same SQL query
multiple times, you can save it as a stored
procedure and call on it whenever
necessary to execute it.

Store an SQL query:

CREATE PROCEDURE
procedure_name
AS
sql_statements
GO;

Execute a stored procedure:

EXEC procedure_name;

DA&.B0,/.8!./01. SELECT .!/,/1)19/C


The SELECT statement is used in SQL
queries to store specific data elements or
fields from a table and return them in a
result set.

The SELECT syntax:

SELECT column_1, column_2, ...


FROM table_name;

To select all data elements from a table,


use

SELECT * FROM table_name;

DD&.B0,/.8!.,9.89E1OC
An SQL index is a lookup table used by the
database search engine to find and
retrieve data quickly. An index can help
make SELECT and WHERE clauses faster but
can slow down the use of UPDATE and
INSERT statements.

To create an index:

CREATE INDEX index_name ON


table_name;

DG&.B0,/.,+1.!()1.'())(9
'M,=!1!.=!1E.;8/0. SELECT .<=1+81!.89
567C
The basic SQL SELECT statement contains
three clauses:

SELECT specifies the table columns to


retrieve

FROM specifies the tables to access

WHERE is optional and specifies which


rows in the FROM tables to use

The GROUP BY clause is used with


aggregate functions to group the result set
according to specified columns.

The HAVING clause functions similarly to


the WHERE clause but allows the use of
aggregate functions.

The ORDER BY clause sorts the result set in


ascending ( ASC ) or descending ( DESC )
order according to a specified column.

When writing your SELECT queries, make


sure that your syntax follows this order:

SELECT column_name(s)
FROM table_name
WHERE condition
GROUP BY column_name(s)
HAVING condition
ORDER BY column_name(s);

D3&.B0,/.,+1.'0,+,'/1+
),982=M,/8(9.?=9'/8(9!C
Character manipulation functions can
edit, change, or reformat character
strings.

For example, you can concatenate two


character strings by passing them into the
CONCAT function using a SELECT query.

DP&.B0,/.8!.,9.567.51+:1+.'=+!(+C
\(;.E(."(=.=!1.8/C
When you want to process result sets one
row at a time, you can use a database
cursor, a control structure that allows you
to traverse records in a database. Cursors

You might also like