LearnThatStack Ace your next interview
Database Technologies

SQL Fundamentals.

Start free Change topic Change
Practice · Questions

All questions

Showing of 44
Beginner 15
01

What is SQL and what are its main components?

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

SQL, short for Structured Query Language, is the standard language for defining, querying and changing data in a relational database. It is declarative, meaning you describe the result and the database decides how to get it. MySQL, PostgreSQL and SQL Server are engines that implement SQL, each with its own extensions.

Its statements fall into four groups:

  • Data Definition Language (DDL) defines structure with CREATE, ALTER and DROP. TRUNCATE counts as DDL too.
  • Data Manipulation Language (DML) reads data with SELECT and changes it with INSERT, UPDATE and DELETE.
  • Data Control Language (DCL) controls access permissions with GRANT and REVOKE.
  • Transaction Control Language (TCL) manages transactions with COMMIT, ROLLBACK and SAVEPOINT.
Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

02

What's the difference between DELETE, TRUNCATE, and DROP?

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

DELETE removes chosen rows, TRUNCATE removes every row but keeps the table, and DROP removes the table itself along with its data.

  • DELETE removes the rows its WHERE clause matches, one row at a time. Delete triggers fire, the change can be rolled back, and it is slow on large tables.
  • TRUNCATE empties the whole table without scanning it, so it is much faster than DELETE. It does not fire delete triggers, and MySQL and SQL Server also reset the auto-increment counter.
  • DROP deletes the table definition together with its data, indexes and constraints.

Rollback depends on the engine. MySQL commits TRUNCATE and DROP immediately, so neither can be rolled back there. PostgreSQL and SQL Server can roll back a TRUNCATE inside a transaction.

DELETE FROM employees WHERE age > 65;  -- Removes specific rows
TRUNCATE TABLE employees;              -- Removes all rows, keeps table
DROP TABLE employees;                  -- Removes entire table
Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

03

What is a Primary Key and what are its characteristics?

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

A primary key is the column, or set of columns, that uniquely identifies each row in a table. The database enforces two rules on it: every value must be unique, and no value may be NULL.

A table can have only one primary key, and the database creates an index on it automatically, so lookups by key are fast. Key values should also stay stable once assigned, because foreign keys point at them, but that is a design rule the database does not enforce.

A UNIQUE constraint also blocks duplicates, and a table can have several of them. Unlike a primary key, it accepts NULL. PostgreSQL and MySQL allow many NULL values in a unique column, while SQL Server allows only one.

CREATE TABLE employees (
    emp_id INT PRIMARY KEY,
    name VARCHAR(100) NOT NULL
);
Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

04

What's the difference between WHERE and HAVING clauses?

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

WHERE filters individual rows before they are grouped, and HAVING filters the groups after GROUP BY has formed them.

WHERE runs first, so it cannot use aggregate functions such as COUNT or AVG, because the groups do not exist yet. HAVING runs after grouping, so it can test those results, such as keeping only departments with more than five employees.

A condition that needs no aggregate belongs in WHERE. Filtering early means fewer rows reach the grouping step, which makes the query cheaper.

-- WHERE filters before grouping
SELECT department, COUNT(*) 
FROM employees 
WHERE salary > 50000 
GROUP BY department;
-- HAVING filters after grouping
SELECT department, COUNT(*) 
FROM employees 
GROUP BY department 
HAVING COUNT(*) > 5;
Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

05

What's the difference between UNION and UNION ALL?

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

UNION combines the rows of two queries and removes duplicate rows, while UNION ALL combines them and keeps every row, duplicates included.

Removing duplicates costs work, because the database has to sort or hash the combined rows to find repeats. So UNION ALL is usually faster. UNION also removes repeats that sit inside one input, not only the ones shared by both.

Both need the same number of columns in each query, in the same order, with compatible data types. The result takes its column names from the first query.

Use UNION ALL when the rows are already distinct, or when duplicates carry meaning, such as when counting events. Use UNION when each distinct row should appear once.

SELECT name FROM employees_2023
UNION                    -- Removes duplicates
SELECT name FROM employees_2024;
SELECT name FROM employees_2023
UNION ALL               -- Keeps all rows
SELECT name FROM employees_2024;
Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

06

What are constraints and what types are available?

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

Constraints are rules the database enforces on column values, so bad data is rejected when it is written. The main types are:

  • NOT NULL stops a column from holding NULL.
  • UNIQUE stops two rows from sharing a value.
  • PRIMARY KEY combines NOT NULL and UNIQUE to identify each row.
  • FOREIGN KEY keeps referential integrity by requiring each value to match a row in another table.
  • CHECK rejects values that fail a condition, such as a total of zero or less.
  • DEFAULT supplies a value when an insert gives none.

A CHECK also passes when its condition is NULL, so pair it with NOT NULL when the column must have a value.

CREATE TABLE orders (
    order_id INT PRIMARY KEY,
    customer_id INT NOT NULL,
    order_date DATE DEFAULT (CURRENT_DATE),
    total_amount DECIMAL(10,2) CHECK (total_amount > 0),
    FOREIGN KEY (customer_id) REFERENCES customers(id)
);
Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

07

How do you handle NULL values in SQL?

Part of Pro
08

What's the difference between a view and a table?

Part of Pro
09

What's the difference between CHAR and VARCHAR data types?

Part of Pro
10

What are the different types of database relationships?

Part of Pro
11

What are aggregate functions and how do they work with GROUP BY?

Part of Pro
12

How do you perform case-insensitive searches in SQL?

Part of Pro
13

What are SQL's built-in functions, and what types exist?

Part of Pro
14

What do INTERSECT and EXCEPT do, and how do they differ from UNION?

Part of Pro
15

Explain the different types of SQL JOINs.

Part of Pro
Intermediate 23
16

Explain the concept of database normalization and its forms.

Part of Pro
17

What are indexes and how do they improve query performance?

Part of Pro
18

What are subqueries and what types exist?

Part of Pro
19

Explain the difference between clustered and non-clustered indexes.

Part of Pro Visual
20

What are Common Table Expressions (CTEs) and when would you use them?

Part of Pro
21

What are stored procedures and their advantages?

Part of Pro
22

What's the difference between correlated and non-correlated subqueries?

Part of Pro
23

What are triggers and when should you use them?

Part of Pro
24

How do you find duplicate records in a table?

Part of Pro
25

Explain the execution order of SQL clauses.

Part of Pro Visual
26

What's the difference between RANK(), DENSE_RANK(), and ROW_NUMBER()?

Part of Pro
27

Explain the concept of database transactions.

Part of Pro
28

What are the advantages and disadvantages of using indexes?

Part of Pro
29

What's the difference between EXISTS and IN operators?

Part of Pro Visual
30

How do you implement pagination in SQL?

Part of Pro Visual
31

What are user-defined functions and how do they differ from stored procedures?

Part of Pro
32

What is a self-join and when would you use it?

Part of Pro
33

What do the LAG and LEAD window functions do?

Part of Pro Visual
34

How do you write an upsert in SQL, and why avoid select-then-insert?

Part of Pro
35

Explain ACID properties in database transactions.

Part of Pro
36

What are Window Functions and how do they differ from aggregate functions?

Part of Pro
37

How do you calculate running totals and moving averages?

Part of Pro Visual
38

Explain SQL injection and how to prevent it.

Part of Pro Visual
Expert 6
39

Explain different isolation levels in databases.

Part of Pro
40

How do you optimize slow SQL queries?

Part of Pro
41

Explain the concept of database locks and their types.

Part of Pro
42

How do you handle hierarchical data in SQL?

Part of Pro Visual
43

How do you implement row-level security in SQL?

Part of Pro
44

Explain database partitioning and its benefits.

Part of Pro Visual

No matches

Try a different filter or search term.

Know someone prepping for SQL Fundamentals? Send them this set.
Pro · $10/mo

38 of 44 SQL Fundamentals answers are in Pro.

Full answers, code samples, and AI explanations that go simpler or deeper. Cancel anytime.

  • Full answers + code
  • AI explanations, simpler or deeper
  • 1,000 AI credits / month
  • Cancel anytime

Change topic

Pick a different technology or stack. Your current topic stays put until you choose a new one.

Technologies
No technologies match “”.
Cross-cutting topics
No topics match “”.
By role
Stacks & frameworks

MEAN

MongoDB, Express, Angular, Node.js

MERN

MongoDB, Express, React, Node.js

LAMP

Linux, Apache, MySQL, PHP

Django

Python Full-Stack Development

Ruby on Rails

Convention over Configuration

Serverless on AWS

Serverless Architecture on AWS

Flutter Mobile

Flutter Cross-Platform Mobile Development

Spring Boot

Enterprise Java Development

.NET

Microsoft Ecosystem

Vue

Vue.js, Vite, TypeScript, Tailwind, Node.js

Go Backend

Golang, gRPC, PostgreSQL, Redis, RabbitMQ

FastAPI

Python, FastAPI, SQLAlchemy, PostgreSQL

React Native

React, TypeScript, Redux, Firebase

iOS Native

Swift, SwiftUI, UIKit, Firebase

Android Native

Java, Jetpack Compose, Firebase

DevOps / Platform

Docker, Kubernetes, Terraform, CI/CD

AI Engineer

LLMs, RAG, Agents, Evals

AI-Powered Developer

Claude Code, Copilot, Agentic Workflows

Core SWE Interview Prep

Data structures, algorithms, OS, concurrency, networking, git