SQL Full Course Tutorial
- 90Unfamiliar
- 0Learning
- 0Familiar
- 0Mastered
- spaceFlip card
- KI knew it
- DI didn't know it
- āPrevious card
- āNext card
What does SQL stand for and what is its purpose?
Structured Query Language; it is the language used to communicate between you and a database.
Or swipe the card
90 cards
What does SQL stand for and what is its purpose?
Structured Query Language; it is the language used to communicate between you and a database.
What is a database?
A collection of data that can hold a massive amount of data (e.g., up to nine quintillion rows).
What are the two main types of databases?
Relational and non-relational (NoSQL).
What does CRUD stand for in SQL?
Create, Read, Update, Delete.
What is DQL?
Data Query Language; used for reading data (SELECT statements).
What is DML?
Data Manipulation Language; used for creating, updating, and deleting data in existing tables (INSERT, UPDATE, DELETE, MERGE).
What is DDL?
Data Definition Language; used for creating and deleting schemas and tables (CREATE, ALTER, DROP, TRUNCATE).
What is DuckDB?
A blazingly fast, free, open-source relational database focused on analytics, used for this course.
What is MotherDuck?
A managed cloud platform that allows hosting DuckDB databases in the cloud, providing data warehousing capabilities.
What are the four attributes that define a data warehouse according to Bill Inmon?
Subject-oriented, non-volatile, integrated, and time-variant.
What is a fact table in a star schema?
A central table that stores measurable quantitative data about business events or transactions.
What is a dimension table in a star schema?
Supporting tables that provide descriptive context about the facts, answering who, what, when, and where.
What is a primary key?
A unique identifier for a column in a table; it must be unique and not null.
What is a foreign key?
A column in one table that references the primary key of another table, establishing a relationship.
What is an entity relationship diagram (ERD)?
A map of the data warehouse showing tables, columns, primary and foreign keys, and relationships between tables.
What are the three main types of relationships in an ERD?
One-to-one, one-to-many, and many-to-many.
What is a star schema?
A design pattern with one central fact table surrounded by dimension tables, shaped like a star.
What is a snowflake schema?
A variation of the star schema where dimension tables are normalized into sub-dimension tables.
What is a bridge table?
A table that resolves a many-to-many relationship between two other tables by acting as an intermediary.
What is a CTE (Common Table Expression)?
A temporary named result set defined within a WITH clause, existing only during the execution of the query.
What is a subquery?
A query nested inside another query, enclosed in parentheses.
What is the difference between a left join and an inner join?
Left join returns all rows from the left table and matching rows from the right; inner join returns only rows with matches in both tables.
What is a full outer join?
Returns all rows from both tables, with NULLs where there is no match.
What is the order of execution of SQL clauses?
FROM/JOIN, WHERE, GROUP BY, HAVING, SELECT, ORDER BY, LIMIT.
What is the difference between COUNT(*) and COUNT(column)?
COUNT(*) counts all rows including NULLs; COUNT(column) counts only non-NULL values in that column.
What does GROUP BY do?
Groups rows that have the same values in specified columns into summary rows, allowing aggregate functions to be applied per group.
What is the HAVING clause used for?
To filter groups based on aggregate functions, after GROUP BY.
What is the median function and why is it preferred over average for salary analysis?
Median finds the middle value; it is less influenced by extreme outliers than average, giving a more representative central tendency.
What is a window function?
A function that performs a calculation across a set of rows related to the current row, without collapsing the rows into a single output.
What does PARTITION BY do in a window function?
Divides the result set into partitions (groups) and applies the window function separately within each partition.
What do LAG and LEAD functions do?
LAG accesses a previous row's value; LEAD accesses a subsequent row's value within the same partition.
What is the difference between RANK and DENSE_RANK?
RANK leaves gaps after ties; DENSE_RANK does not leave gaps.
What is a CASE expression?
A way to apply conditional logic in SQL, returning a value based on specified conditions.
What does the COALESCE function do?
Returns the first non-NULL value in a list of expressions.
What does NULLIF do?
Returns NULL if two expressions are equal, otherwise returns the first expression.
What is the difference between DELETE and TRUNCATE?
DELETE removes specific rows based on a WHERE condition; TRUNCATE removes all rows from a table but keeps the table structure.
What is the MERGE statement used for?
To perform INSERT, UPDATE, or DELETE operations in a single statement, often used for incremental data loading (upsert).
What is a view?
A virtual table defined by a SQL query; it does not store data but provides a way to see data from underlying tables.
What is a temporary table?
A table that exists only for the duration of a session or transaction, often used for intermediate results.
What is the purpose of the EXPLAIN command?
To display the query execution plan, showing how the database will execute the query without actually running it.
What does UNION do compared to UNION ALL?
UNION combines results from two queries and removes duplicates; UNION ALL combines results and keeps all rows, including duplicates.
What does INTERSECT do?
Returns rows that appear in both result sets, with duplicates removed.
What does EXCEPT (or MINUS) do?
Returns rows from the first query that are not in the second query, with duplicates removed.
What is an array in DuckDB?
An ordered collection of elements of the same type, denoted by square brackets.
What is a struct?
A composite data type containing multiple named fields, denoted by curly braces.
How do you access elements in an array?
Using square bracket index notation, e.g., array[1] for the first element.
How do you access fields in a struct?
Using dot notation, e.g., struct.field_name.
What function is used to unnest an array?
The UNNEST function.
What is an OLTP database?
Online Transaction Processing; optimized for high-velocity writes and transactional applications.
What is an OLAP database?
Online Analytical Processing; optimized for large scans, aggregations, and analytical queries.
What is a slowly changing dimension (SCD)?
A technique to track changes in dimension tables over time, with types like Type 0 (fixed), Type 1 (overwrite), Type 2 (add new row), etc.
What is the purpose of the gitignore file?
To specify files and directories that should not be tracked by Git, such as sensitive credentials, large data files, or environment-specific files.
What is a branch in Git?
An independent line of development that allows working on features or fixes without affecting the main codebase.
What is a pull request (PR)?
A proposal to merge changes from one branch into another, often used for code review and collaboration.
What is the difference between git fetch and git pull?
git fetch downloads data from the remote repository but does not merge; git pull downloads and merges into the current branch.
What is a data mart?
A curated subset of data from a data warehouse, designed for a specific business function or analytical use case.
What is an ELT pipeline?
Extract, Load, Transform: data is extracted from sources, loaded into the target, then transformed.
What is idempotency in data engineering scripts?
The property that a script can be run multiple times without causing errors or side effects, producing the same result each time.
What is the purpose of the information_schema in DuckDB?
A collection of read-only views that provide metadata about the database, such as tables, columns, and constraints.
What does the DESCRIBE command do in DuckDB?
Returns information about columns in a table, including data type, nullability, and key constraints.
What is the difference between CAST and :: operator for type conversion?
CAST(expression AS type) is the standard SQL function; :: is a PostgreSQL/commonly used operator syntax.
What is the purpose of the date_trunc function?
To truncate a timestamp to a specified precision (e.g., month, year), returning the start of that unit.
What does the EXTRACT function do?
Retrieves a specific part (e.g., year, month, day) from a date or timestamp as an integer.
How can you convert a timestamp without time zone to one with time zone in DuckDB?
Use AT TIME ZONE twice: first to specify the source time zone, then to convert to the target time zone.
What is a batch processing pipeline?
A pipeline that processes data in groups at scheduled intervals (e.g., daily), updating only new or changed rows.
What is the purpose of the array_agg function?
To aggregate values from a column into an array (list), optionally ordered.
What is the struct_pack function used for?
To create a struct from named arguments.
What is a bridge table in data modeling?
A table that resolves a many-to-many relationship by holding foreign keys from both related tables.
What is the difference between a view and a materialized view?
A view is a virtual table that runs a query each time it's accessed; a materialized view stores the query result physically and can be refreshed.
What is the purpose of the DISTINCT keyword?
To return only unique values from a column or combination of columns.
What is the difference between WHERE and HAVING?
WHERE filters rows before aggregation; HAVING filters groups after aggregation.
What is a cross join?
Returns the Cartesian product of two tables, combining every row from the first table with every row from the second.
What is the difference between CHAR and VARCHAR?
CHAR is fixed-length and pads with spaces; VARCHAR is variable-length and only uses needed space.
What is the BOOLEAN data type in SQL?
A data type that stores TRUE or FALSE values, often represented internally as 1 or 0.
What is a composite primary key?
A primary key composed of two or more columns that together uniquely identify a row.
What is the purpose of the ON DELETE CASCADE constraint?
Automatically delete related rows in child tables when a row in the parent table is deleted.
What is a surrogate key?
An artificial, system-generated unique identifier for a table row, often used as the primary key.
What is the difference between a flat table and a normalized table?
A flat table (denormalized) contains all data in one table with possible redundancy; normalized tables split data into multiple related tables to reduce redundancy.
What is the purpose of the LIMIT clause?
To restrict the number of rows returned by a query.
What is the difference between NVL and COALESCE?
NVL is a function in some databases (e.g., Oracle) that takes two arguments; COALESCE is the standard SQL function that takes multiple arguments and returns the first non-NULL.
What is a recursive CTE?
A CTE that references itself, allowing queries to process hierarchical or tree-structured data.
What is the purpose of the QUALIFY clause in some databases?
To filter the results of window functions, similar to how HAVING filters aggregations.
What is the difference between a clustered and a non-clustered index?
Clustered index determines the physical order of data on disk; non-clustered index is a separate structure that points to the data.
What is the purpose of the ANALYZE command?
To collect statistics about tables and indexes, helping the query optimizer make better decisions.
What is a transaction in SQL?
A sequence of one or more SQL operations executed as a single unit, either all succeed or all fail.
What is the difference between COMMIT and ROLLBACK?
COMMIT permanently saves the changes made in the current transaction; ROLLBACK undoes them.
What is a self-join?
A join of a table with itself, using different aliases to compare rows within the same table.
What is the difference between a role and a user in database security?
A user is an individual account; a role is a collection of permissions that can be assigned to multiple users.
What is a star join?
A query optimization technique used in OLAP databases where the fact table is joined to multiple dimension tables in a star-shaped pattern.
What is the purpose of the CASE statement in SQL?
To return a value based on conditional logic, similar to if-else statements.

Ask anything
We've read this whole study set, so questions about it get the best answers.