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
-
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.
-
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
-
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
-
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
-
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
-
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
-
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
-
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
-
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)
-
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:
SELECTandWHERE: choosing columns and filtering rows.ORDER BY: sorting the result.GROUP BYand aggregate functions:COUNT,SUM,AVG,MINandMAX.HAVING: filtering groups, and how it differs fromWHERE.TOP,ALLandDISTINCT: limiting results and removing duplicates.CASE WHEN: conditions inside a query.COALESCE,ISNULLandNULLIF: working withNULLvalues.JOIN: combining tables withINNER,LEFT,RIGHTandFULL JOIN.- Subqueries: a query inside another query.
UNION,INTERSECTandEXCEPT: 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.