Back to Insights

Top SQL Interview Questions and Answers for Beginners

Senesly Team · Product7 min read

SQL (Structured Query Language) is used to store, manage, retrieve and organise data in relational databases. It is an important skill for data analysts, software developers, database administrators and many other IT professionals.

If you are preparing for your first technical interview, understanding basic SQL concepts and practising commonly asked questions can help you prepare more effectively. Interviewers often ask about SQL commands, filtering, joins, aggregate functions, constraints and database concepts to assess a candidate's understanding.

In this guide, we cover the most common SQL interview questions and answers for beginners, with simple explanations and examples to help you understand the concepts.

1.What Is SQL?

SQL stands for Structured Query Language. It is a language used to communicate with relational databases. It allows users to create tables, insert data, update records, delete information and retrieve data.

SQL is commonly used with database systems such as MySQL, PostgreSQL, SQL Server and Oracle.

Example:

SELECT * FROM employees;

This query retrieves all columns and records from the employees table.

2.What Is a Database?

A database is an organised collection of information that can be stored, accessed and managed electronically.

For example, a company's database may contain employee names, salaries, department details, customer information and sales records.

Databases help organisations manage information efficiently and retrieve the required data when needed.

3.What Is the Difference Between SQL and MySQL?

SQL is a query language used to interact with relational databases. MySQL is a relational database management system that uses SQL to manage and retrieve information.

SQLMySQL
A query languageA database management system
Used to communicate with databasesUsed to store and manage databases
Provides commands and syntaxImplements SQL commands
Not a database software itselfDatabase software

4.What Are the Different Types of SQL Commands?

SQL commands are commonly divided into five categories:

CategoryPurposeExamples
DDLDefines database structuresCREATE, ALTER, DROP
DMLModifies dataINSERT, UPDATE, DELETE
DQLRetrieves dataSELECT
DCLControls access permissionsGRANT, REVOKE
TCLManages transactionsCOMMIT, ROLLBACK

Understanding these categories helps beginners recognise the purpose of different SQL statements.

5.What Is a Primary Key?

A primary key is a column or combination of columns that uniquely identifies each record in a table.

A primary key must contain unique values and cannot contain NULL values.

Example:

CREATE TABLE employees (
employee_id INT PRIMARY KEY,
employee_name VARCHAR(100),
department VARCHAR(50)
);

Here, employee_id is the primary key because it uniquely identifies each employee.

6.What Is a Foreign Key?

A foreign key is a column that creates a relationship between two tables. It references a primary key or another eligible unique key in a related table.

Example:

CREATE TABLE departments (
department_id INT PRIMARY KEY,
department_name VARCHAR(100)
);

CREATE TABLE employees ( employee_id INT PRIMARY KEY, employee_name VARCHAR(100), department_id INT, FOREIGN KEY (department_id) REFERENCES departments(department_id) );

In this example, department_id in the employees table connects employees with their respective departments.

7.What Is the Difference Between WHERE and HAVING?

Both WHERE and HAVING are used to filter data, but they work at different stages of a query.

  • WHERE: Filters individual rows before grouping.
  • HAVING: Filters grouped results after aggregation.

Example using WHERE:

SELECT *
FROM employees
WHERE salary > 50000;

Example using HAVING:

SELECT department, COUNT(*) AS total_employees
FROM employees
GROUP BY department
HAVING COUNT(*) > 5;

The second query displays departments having more than five employees.

8.What Is the Difference Between DELETE, DROP and TRUNCATE?

These commands are used to remove data or database objects, but their purposes differ.

CommandPurpose
DELETERemoves selected or all rows from a table
TRUNCATERemoves all rows from a table while retaining its structure
DROPRemoves the table or database object itself

Example:

DELETE FROM employees
WHERE employee_id = 10;

This removes the employee record with ID 10.

TRUNCATE TABLE employees;

This removes all rows from the table.

DROP TABLE employees;

This removes the table structure and the table itself.

The exact behaviour regarding transactions, identity counters and rollback may depend on the database system.

9.What Are SQL Joins?

SQL joins are used to combine data from two or more tables based on a related column.

The main types of joins are:

  • INNER JOIN
  • LEFT JOIN
  • RIGHT JOIN
  • FULL OUTER JOIN

Example: INNER JOIN

SELECT employees.employee_name,
departments.department_name
FROM employees
INNER JOIN departments
ON employees.department_id = departments.department_id;

This query returns employees whose department matches a record in the departments table.

10.What Is the Difference Between INNER JOIN and LEFT JOIN?

An INNER JOIN returns matching records from both tables.

A LEFT JOIN returns all records from the left table and matching records from the right table. If there is no match, the right-side columns contain NULL.

INNER JOINLEFT JOIN
Returns matching records onlyReturns all left-table records
Unmatched rows are excludedUnmatched left rows are included
Useful for finding common recordsUseful for finding all records from one table

11.What Is the GROUP BY Clause?

The GROUP BY clause groups rows that have the same value in one or more columns. It is often used with aggregate functions such as COUNT, SUM, AVG, MIN and MAX.

Example:

SELECT department,
COUNT(*) AS employee_count
FROM employees
GROUP BY department;

This query counts the number of employees in each department.

12.What Are Aggregate Functions in SQL?

Aggregate functions perform calculations on multiple rows and return a single result for each group or the entire result set.

Common aggregate functions include:

  • COUNT() – counts records
  • SUM() – calculates the total
  • AVG() – calculates the average
  • MIN() – returns the minimum value
  • MAX() – returns the maximum value

Example:

SELECT AVG(salary) AS average_salary
FROM employees;

This query calculates the average salary of employees.

13.What Is the Difference Between UNION and UNION ALL?

Both UNION and UNION ALL combine results from multiple SELECT statements.

  • UNION removes duplicate rows from the combined results.
  • UNION ALL includes duplicate rows.

Example:

SELECT city FROM customers
UNION
SELECT city FROM suppliers;

This returns a combined list of cities without duplicate rows.

SELECT city FROM customers
UNION ALL
SELECT city FROM suppliers;

This includes duplicates if the same city appears in both results.

14.What Is a NULL Value in SQL?

NULL represents missing, unknown or unavailable data. It is different from zero or an empty string.

To check for NULL values, use IS NULL or IS NOT NULL.

Example:

SELECT *
FROM employees
WHERE department IS NULL;

This query retrieves employees whose department value is missing.

15.What Is the ORDER BY Clause?

ORDER BY is used to sort query results in ascending or descending order.

  • ASC sorts in ascending order.
  • DESC sorts in descending order.

Example:

SELECT employee_name, salary
FROM employees
ORDER BY salary DESC;

This query displays employees from the highest salary to the lowest salary.

16.What Is a Subquery in SQL?

A subquery is a query written inside another SQL query. It can be used to retrieve information that helps the outer query perform its operation.

Example:

SELECT employee_name, salary
FROM employees
WHERE salary > (
SELECT AVG(salary)
FROM employees
);

This query retrieves employees whose salaries are higher than the average salary of all employees.

17.What Is the Difference Between a Unique Key and a Primary Key?

A primary key uniquely identifies every record in a table. A unique key also prevents duplicate values in a column or column combination.

Primary KeyUnique Key
Uniquely identifies each rowPrevents duplicate key values
Cannot contain NULLNULL handling depends on the database
One primary key constraint per tableMultiple unique constraints may be defined
Used as the main identifierUsed to enforce uniqueness

18.What Is an Index in SQL?

An index is a database structure that can help retrieve records more efficiently. It is commonly created on columns that are frequently used in searches, joins or sorting.

Example:

CREATE INDEX idx_employee_name
ON employees(employee_name);

An index may improve query performance, but too many indexes can increase storage usage and slow down operations that modify data.

19.What Is Normalisation in SQL?

Normalisation is the process of organising data into related tables to reduce unnecessary duplication and improve data consistency.

Common normalisation levels include:

  • 1NF: Each column contains atomic values, with no repeating groups.
  • 2NF: Meets 1NF and removes partial dependencies on a composite key.
  • 3NF: Meets 2NF and removes transitive dependencies of non-key attributes.

Normalisation helps maintain organised databases and reduces common data-management problems.

20.How Do You Find Duplicate Records in SQL?

The GROUP BY clause combined with HAVING can be used to identify repeated values.

Example:

SELECT email, COUNT(*) AS total
FROM employees
GROUP BY email
HAVING COUNT(*) > 1;

This query identifies email addresses that appear more than once in the employees table.

Tips to Prepare for SQL Interviews

Preparing for SQL interviews requires more than memorising definitions. Practise writing queries and understand why each command works.

  • Practise SELECT, WHERE, ORDER BY and GROUP BY.
  • Understand joins and relationships between tables.
  • Work with aggregate functions and subqueries.
  • Practise SQL problems using sample databases.
  • Learn how to explain your query logic clearly.
  • Prepare for follow-up questions about query performance and database design.
  • Practise answering technical questions aloud.

If you are preparing for interviews with AI support, you can also explore an AI interview assistant to practise explaining technical concepts, improve your response structure and prepare for interview scenarios.

How AI Can Help You Prepare for SQL Interviews

AI tools can help candidates practise technical interview questions, review their explanations and work on areas where they need improvement. They can also help simulate interview conversations and provide additional practice questions.

Candidates exploring interview preparation technology can learn about a cheapest AI interview assistant or compare features of a best AI interview assistant when evaluating available tools. If researching AI support for online interview environments, understand the features and limitations of an undetectable AI interview assistant and always consider the interview platform's rules and employer policies.

The best preparation approach is to build your SQL knowledge, practise solving real problems and become comfortable explaining your reasoning independently.

More insights →

Try Senesly - AI assistant for Zoom, Meet & Teams.

See pricing