SQL Tutorial

This SQL Tutorial helps you master SQL quickly and effectively with clear concepts, hands-on examples, and interactive quizzes.

Whether you’re a software developer, database administrator, data analyst, or data scientist, this SQL tutorial will help you unlock the power of SQL for managing and analyzing data.

SQL (Structured Query Language) is the standard language for data interaction in Relational Database Management Systems (RDBMS).

Start your SQL journey with me now and master the skills to work with data confidently!

Section 1. Introduction to SQL #

Section 2. Querying Data #

  • SELECT – Retrieves data from a table.

Section 3. Sorting Rows #

Section 4. Filtering Rows #

  • DISTINCT  – Retrieves distinct values from a result set.
  • LIMIT – Limits the number of rows a query returns.
  • FETCH – Skips N rows in a result set before starting to return any rows.
  • WHERE Clause – Filters rows based on a condition.
  • AND operator – Combines two Boolean expressions using the AND logical operator.
  • OR operator – Combines two boolean expressions using the OR logical operator.
  • BETWEEN Operator – Guides you to use the BETWEEN operator to select data within a range of values.
  • IN Operator – Return true if a value is in a list of values.
  • LIKE Operator –  Queries data based on a specified pattern.
  • IS NULL Operator – Understands NULL and how to check whether a value is NULL.
  • NOT operator – Negates a Boolean expression using the NOT operator.

Section 5. Joining Multiple Tables #

  • INNER JOIN – Merges rows from two tables based on a condition and returns only the matching rows in both tables.
  • LEFT JOIN – Returns all rows from the left table and matching rows from the right table; if there are no matching rows, use NULL for columns of the right table.
  • RIGHT JOIN – Returns all rows from the right table and matching rows from the left table; if there are no matching rows, use NULL for columns of the left table.
  • FULL OUTER JOIN – Joins multiple tables by including rows from both tables whether or not the rows have matching rows from another table.
  • CROSS JOIN – Returns a result set that combines every row from the first table with every row from the second table.
  • SELF JOIN – Combines rows within the same table based on a related column.

Section 6. Grouping Rows #

  • GROUP BY– Arranges rows into groups and applies an aggregate function to each group.
  • HAVING – Filters groups of rows based on a condition.
  • GROUPING SETS – Defines multiple groupings in a single query.
  • ROLLUP – Generates multiple grouping sets considering the hierarchy of the input columns.
  • CUBE – Generates subtotals and grand totals for a set of columns in a query, with the capacity to create all possible combinations of groupings.

Section 7. SET Operators #

  • UNION – Combines result sets of two or more queries into a single result set.
  • INTERSECT  – Returns the common rows between two result sets.
  • MINUS – Returns the unique rows from one result set that do not appear in another.

Section 8. Working with Tables #

  • CREATE TABLE – Creates a new table in the database.
  • PRIMARY KEY –  Defines a primary key for a table.
  • NOT NULL  – Ensures that the values inserted into or updated to a column are not NULL.
  • DROP TABLE – Drops a table from the database.
  • Add a new column to a table – Adds a new column to an existing table.
  • Drop a column – Removes a column from a table.
  • FOREIGN KEY – Defines foreign key constraints.
  • UNIQUE – Ensures the uniqueness of values in a column or a set of columns.
  • CHECK – Validates data before storing it in one or more columns based on a Boolean expression.
  • ALTER TABLE – Modifies the structure of an existing table.

Section 9. Modifying data #

  • INSERT – Inserts one or more rows into a table.
  • UPDATE – Updates existing data in a table.
  • DELETE – Deletes data from a table permanently.
  • TRUNCATE TABLE – Deletes all data in a big table quickly and efficiently.

Section 10. Views & Triggers #

  • Views – Creates a view in the database.
  • Triggers – Creates a trigger associated with a table and automatically responds to an event that occurs in the table.

Section 11. Conditional Expressions & Functions #

  • CASE Expression – Adds if-else logic to the SQL statements.
  • COALESCE – Returns the first non-null values in a set of values.
  • NULLIF – Compares two arguments and returns NULL if they are equal or the first argument otherwise.

Section 12. Aggregate Functions #

  • Aggregate functions – Returns a value such as min, max, average, sum, and count for a set of values.
  • AVG – Returns the average value of a set.
  • COUNT – Returns the number of items in a set.
  • SUM – Returns the sum of all or distinct items of a set.
  • MAX – Returns the maximum value in a set.
  • MIN – Returns the minimum value in a set.

Section 13. Subquery #

  • Subquery – Creates a query within another query, providing result sets to the outer query.
  • Correlated Subquery – Constructs a subquery that uses values from the outer query.
  • EXISTS – Returns true if the subquery contains any rows.
  • ALL – Compares a value with a set of values and returns true if the comparison is true for every value in the set.
  • ANY – Compares a value with a set of values and returns true if the comparison is true for at least one value in the set.