SQL interview questions

Want to become an expert in cracking SQL interview questions/Database interview questions?

Start with practicing the questions below. Whether a question involves multiple choice or live coding, we will give you hints as you go and tell you if your answers are correct or incorrect.

After that, take our timed public SQL interview questions test.

To use our service for testing developers, purchase one of the paid plans for companies.


1. Enrollment
SQL Conditions Public

A table containing the enrollment year has incorrect data in records with ids between 20 and 100.

Select all queries below that, for the faulty records, set the year to 2015.

Easy  
2min
Solve question

2. Students
SQL Aggregation Public

Select all queries that return number of students whose first name is John.

TABLE student
  id INTEGER NOT NULL PRIMARY KEY
  firstName VARCHAR(30) NOT NULL
  lastName VARCHAR(30) NOT NULL
Easy  
2min
Solve question

3. WebShop
SQL Joins Public

Each item in a web shop belongs to a different seller. To ensure service quality, each seller has a rating.

The data are kept in the following two tables:

TABLE sellers
  id INTEGER PRIMARY KEY,
  name VARCHAR(30) NOT NULL,
  rating INTEGER NOT NULL

TABLE items
  id INTEGER PRIMARY KEY,
  name VARCHAR(30) NOT NULL,
  sellerId INTEGER REFERENCES sellers(id)

Write a query that selects the item name and the name of its seller for each item that belongs to a seller with a rating of more than 4.

See the example case for more details.

Easy  
7min
Solve question

4. Pets
SQL Joins Public

Information about pets is kept in two separate tables:

TABLE dogs
  id INTEGER PRIMARY KEY,
  name VARCHAR(50) NOT NULL

TABLE cats
  id INTEGER PRIMARY KEY,
  name VARCHAR(50) NOT NULL

Identify all the queries that select all distinct pet names.

Hard  
3min
Solve question

5. Workers
SQL Subqueries Public

Given the following data definition, select all queries that return a list of employees who are not managers.

TABLE emp
  id INTEGER NOT NULL PRIMARY KEY
  mgrId INTEGER REFERENCES emp (id)
  name VARCHAR(30) NOT NULL
Hard  
3min
Solve question

6. Sessions
SQL Aggregation Public

App usage data are kept in the following table:

TABLE sessions
  id INTEGER PRIMARY KEY,
  userId INTEGER NOT NULL,
  duration DECIMAL NOT NULL

Write a query that selects userId and average session duration for each user who has more than one session.

See the example case for more details.

Hard  
7min
Solve question

If you feel ready, take one of our timed public SQL interview questions tests:

  • C# and SQL online test (Easy / Hard)
  • C++ and SQL online test (Easy / Hard)
  • HTML/CSS, JavaScript, and SQL online test (Easy / Hard)
  • HTML/CSS, JavaScript, C#, and SQL online test (Easy / Hard)
  • HTML/CSS, JavaScript, Java, and SQL online test (Easy / Hard)
  • HTML/CSS, JavaScript, PHP, and SQL online test (Easy / Hard)
  • HTML/CSS, JavaScript, Python, and SQL online test (Easy / Hard)
  • HTML/CSS, JavaScript, Ruby, and SQL online test (Easy / Hard)
  • HTML/CSS, JavaScript, SQL, and C# Algorithms online test (Easy / Hard)
  • HTML/CSS, JavaScript, SQL, and Java Algorithms online test (Easy / Hard)
  • Java and SQL online test (Easy / Hard)
  • JavaScript and SQL online test (Easy / Hard)
  • PHP and SQL online test (Easy / Hard)
  • Python and SQL online test (Easy / Hard)
  • Ruby and SQL online test (Easy / Hard)
  • SQL online test (Easy / Hard)
  • SQL and C# Algorithms online test (Easy / Hard)
  • SQL and C++ Algorithms online test (Easy / Hard)
  • SQL and Java Algorithms online test (Easy / Hard)
Not exactly what you are looking for? Go to our For developers section.