SQL query execution

This section will be dedicated to explain how to retrieve the data recorded in the tables through queries execution. We will see step-by-step the SELECT statement clauses, how to filter the required information, how to order and group the results and how to retrieve data from multiple independent tables from a single statement using relationships

10 lessons 10 with examples you can run

  1. SELECT statement in SQL

    SELECT, is the DML command that allows you to query the data from the database tables and return the records in a table called result set. In this section we will see the main clauses and operators in the handling of statements.

  2. ORDER BY clause in SQL

    ORDER BY is the SELECT clause that allows us to sort out the records in ascending or descending order. This clause will always be placed at the end of the statement

  3. GROUP BY statement and aggregate functions in SQL

    Aggregate functions allow you to perform operations on a result set by returning a single aggregate value. GROUP BY is used to group the results according to the selected column,they are often used with aggregate functions

  4. HAVING clause in SQL

    HAVING filters the groups returned by GROUP BY based on the result of an aggregate function. We will see when to use HAVING and when to use WHERE, with examples you can run in your browser

  5. TOP, ALL and DISTINCT clauses in SQL

    The TOP, ALL and DISTINCT clauses, often known as predicates, are clauses used in queries, generally located in the SELECT before the FROM and used for filtering records

  6. CASE WHEN expression in SQL

    CASE is SQL's conditional: it returns one value or another depending on a list of conditions. We will see simple CASE, searched CASE, how to use it in ORDER BY and how to count with conditions inside SUM or COUNT

  7. COALESCE, ISNULL and NULLIF in SQL

    COALESCE returns the first non-NULL value in a list. We will see how to use it to replace null values, how it differs from SQL Server's ISNULL and what NULLIF is for

  8. JOIN clause in SQL

    JOIN is the clause that allows us to execute queries and return data from several independent but related tables through Foreign Keys. In this section we will see the different types of JOIN and how to apply them

  9. Subquery in SQL

    A SUBQUERY is a nested query within another SELECT, SUBQUERY, or within other SQL statements such as INSERT, UPDATE, or DELETE. They can be located in any of the main clauses of a query (SELECT, FROM or WHERE)

  10. UNION statement in SQL

    UNION is a statement or operator that allows you to join two or more SELECTs by concatenating the execution results into a single result set

What you will learn in this section

This is the part of SQL you will use most: reading data. Everything revolves around SELECT and the clauses that go with it, in the order they are best learned:

  1. SELECT and WHERE: choosing columns and filtering rows.
  2. ORDER BY: sorting the result.
  3. GROUP BY and aggregate functions: COUNT, SUM, AVG, MIN and MAX.
  4. HAVING: filtering groups, and how it differs from WHERE.
  5. TOP, ALL and DISTINCT: limiting results and removing duplicates.
  6. CASE WHEN: conditions inside a query.
  7. COALESCE, ISNULL and NULLIF: working with NULL values.
  8. JOIN: combining tables with INNER, LEFT, RIGHT and FULL JOIN.
  9. Subqueries: a query inside another query.
  10. UNION, INTERSECT and EXCEPT: set operations.

Every lesson in this section has runnable examples. Change the query, press Run and compare your result with the table in the lesson. It is the quickest way to really understand a JOIN or a GROUP BY.

Once you are comfortable with this section, the next step is advanced queries: CTEs, window functions and PIVOT.