SQL Tutorial

This SQL tutorial consists of examples so you can quickly learn to use SQL commands, functions, querying data, conditional statements, set constraints, data types, views.

SQL (Structured Query Language) is used to manipulate data stored in relational database management systems (RDBMS). The SQL language is used in a database to create tables, views, insert data, query, update and delete.

Basic SQL tutorial

We begin the introduction to SQL tutorial by describing the chapters that will help you learn the basics of the SQL language, knowledge that will be useful for managing a relational database. The SQL tutorial chapters are the following:

SQL DDL Statements (Data Definition Language)

CREATE TABLE – learn how to create a table.
ALTER TABLE – show you how to modify a table structure.
DROP TABLE – remove a table from database.
TRUNCATE TABLE – allow to delete all rows from a table.

SQL DML Statements (Data Manipulation Language)

INSERT – insert rows into a table.
UPDATE – update values of existing rows in a table.
DELETE – delete rows from a table.

SQL Constraints

PRIMARY KEY – learn how to create table with a primary key.
FOREIGN KEY – define foreign key to link tables.
UNIQUE – show you how to define a unique constraint.
CHECK – show you how to create a check constraint for a table.

SQL Table Queries

SELECT – query a database table.
DISTINCT -is used to eliminate duplicate rows.
WHERE – is used to return the records that fulfill the conditions after WHERE clause.
AND – OR – show you syntax and examples.
BETWEEN – returns records between two values.
LIKE – return rows if the operand matches a pattern.
ORDER BY – is used to sort the rows in a query.
GROUP BY – is used to group values.
HAVING – show you how to filter groups.
INNER JOIN – returns rows from a query that match the specified join condition.
LEFT JOIN – returns all rows from the left table.
RIGHT JOIN – returns all rows from the right table.
FULL JOIN – returns all rows from the joined tables.
CROSS JOIN – returns the cartesian product of the tables.
SELF JOIN – show you how to use the same table in a self-join.

SQL Aggregate Functions

AVG – returns the average of the value.
COUNT – show you how to count rows.
MAX – is used to get the maximum value.
MIN – is used to get the minimum value.
SUM – calculates the sum of values from a query.