Loading lesson path
SQL Tutorial
Introduction to SQL
SQL Syntax
The SQL SELECT Statement The SELECT statement is used to select data from a database. Example Return data from the Customers table: SELECT CustomerName, City FROM Customers; SELECT Syntax SELECT colu…
SQL SELECT DISTINCT Statement
The SQL WHERE Clause The WHERE clause is used to filter records. The WHERE clause is used to extract only those records that fulfill a specific condition. Example Here we select all customers from Me…
The SQL ORDER BY The ORDER BY keyword is used to sort the result-set in ascending or descending order. The ORDER BY keyword sorts the result-set in ascending order (ASC) by default. Example Sort the…
The SQL AND Operator The WHERE clause can contain one or many AND operators. The AND operator is used to filter records based on more than one condition. Note: The AND operator displays a record if a…
The SQL OR Operator The WHERE clause can contain one or more OR operators. The OR operator is used to filter records based on more than one condition. Note: The OR operator displays a record if any o…
The NOT Operator The NOT operator is used in the WHERE clause to return all records that DO NOT match the specified criteria. It reverses the result of a condition from true to false and vice-versa.…
The SQL INSERT INTO Statement The INSERT INTO statement is used to insert new records in a table. It is possible to write the INSERT INTO statement in two ways: Syntax 1 Specify both the column names…
SQL NULL Values
The SQL UPDATE Statement The UPDATE statement is used to update or modify one or more records in a table. UPDATE Syntax UPDATE table_name SET column1 = value1, column2 = value2, ... WHERE condition ;…
The SQL DELETE Statement The DELETE statement is used to delete existing records in a table. DELETE Syntax DELETE FROM table_name WHERE condition ; Note: Be careful when deleting records in a table!…
The SQL SELECT TOP Clause The SELECT TOP clause is used to limit the number of records to return. The SELECT TOP clause is useful on large tables with thousands of records. Returning a large number o…
SQL Aggregate Functions An aggregate function is a function that performs a calculation on a set of values, and returns a single value. Aggregate functions are often used with the GROUP BY clause of…
SQL MIN() F unction
SQL MAX() Function
SQL COUNT() Function
SQL SUM() Function
SQL AVG() Function
SQL LIKE Operator
SQL Wildcard Characters A wildcard character is used to substitute one or more characters in a string. Wildcard characters are used with the LIKE operator. The LIKE operator is used in a WHERE clause…
The SQL IN Operator The IN operator is used in the WHERE clause to check if a specified column's value matches any value within a provided list. The IN operator functions as a shorthand for multiple…
The SQL BETWEEN Operator The BETWEEN operator is used in the WHERE clause to select values within a specified range. The range is inclusive - the beginning and end values of the range are included in…
SQL Aliases SQL aliases are used to give a column or a table a temporary name. Aliases are used to make column names more readable. An alias only exists for the duration of that query. An alias is cr…
The SQL JOIN Clause The JOIN clause is used to combine rows from two or more tables, based on a related column between them. Here are the different types of JOINs in SQL: (INNER) JOIN : Returns only…
SQL INNER JOIN
SQL LEFT JOIN
SQL RIGHT JOIN The RIGHT JOIN returns all rows from the right table (table2), and only the matched rows from the left table (table1). If there is no match in the left table, the result for the column…
SQL FULL JOIN The FULL JOIN returns all rows when there is a match in either the left or right table. If a row in the left table has no match in the right table, the result set includes the left row'…
SQL Self Join A self join is a regular join, but the table is joined with itself. Self Join Syntax SELECT column_name(s) FROM table1 T1, table1 T2 WHERE condition ; T1 and T2 are different table alia…
The SQL UNION Operator The UNION operator is used to combine the result-set of two or more SELECT statements. The UNION operator automatically removes duplicate rows from the result set. Requirements…
The SQL UNION ALL Operator The UNION ALL operator is used to combine the result-set of two or more SELECT statements. The UNION ALL operator includes all rows from each statement, including any dupli…
The SQL GROUP BY Statement The GROUP BY statement is used to group rows that have the same values into summary rows, like "Find the number of customers in each country". The GROUP BY statement is alm…
The SQL HAVING Clause The HAVING clause is used to filter the results of a GROUP BY query based on aggregate functions. Unlike the WHERE clause, which filters individual rows before grouping, HAVING…
The SQL EXISTS Operator The EXISTS operator is used in a WHERE clause to check whether a subquery returns any rows. The EXISTS operator evaluates to TRUE if the subquery returns at least one row, and…
The SQL ANY Operator The ANY operator is used to compare a value to every value returned by a subquery. The ANY operator evaluates to TRUE if at least one value in the subquery result-set meet the co…
The SQL ALL Operator The ALL operator is used to compare a value to every value returned by a subquery. The ALL operator evaluates to TRUE if every value in the subquery result-set meet the condition…
SQL SELECT INTO Statement
The SQL INSERT INTO SELECT Statement The INSERT INTO SELECT statement is used to copy data from an existing table and insert it into another existing table. The INSERT INTO SELECT statement requires…
The SQL CASE Expression The CASE expression is used to define different results based on specified conditions in an SQL statement. The CASE expression goes through the conditions and stops at the fir…
SQL COALESCE(), IFNULL(), ISNULL(), and NVL() Functions Operations involving NULL values can sometimes lead to unexpected results. SQL has some built-in functions to handle NULL values, and the most…
SQL Stored Procedures
SQL Comments Comments are used to explain SQL code, or to temporarily prevent execution of SQL code (for debugging). Comments are ignored by the database engine. SQL supports single-line comments --,…
SQL Operators SQL operators are keywords and symbols used to perform operations with data values. SQL operators are used in SQL statements like SELECT, WHERE, LIKE, etc. SQL operators is categorized…