SQL Tutorial

The SQL tutorial section provides you with clear, concise, and easy-to-understand SQL. In this section, you will learn how to write complex SQL queries with practical examples. If you don’t know anything about SQL, this tutorial is an excellent start.

Let’s answer a simple but important question.

What is SQL?

  • SQL stands for Structured Query Language.
  • SQL is pronounced as /ˌɛs.kjuːˈɛl/
  • SQL is designed to manipulate data in Relational Database Management System (RDBMS).

So…

What can you do with SQL?

With SQL you can:

  • Manipulate data, including querying and modifying data using data manipulation language (DML).
  • Manage database objects such as tables, views, and indexes using data definition language (DDL).
  • Grant privileges to and revoke privileges from users using data control language (DCL).

Before you start…

Before you start learning SQL, it is important to have a good database management system to practice. These are common database management systems that you should consider:

  • MySQL is the most popular database system. MySQL is also free and open-source. If you are developing web applications, you should use MySQL.
  • Microsoft SQL Server is Microsoft’s Database product widely used in corporate environments. If you are working for a corporate, it makes sense to use Microsoft SQL Server to practice with SQL. Microsoft offers developers and database administrators SQL Server Express Edition that is ideal for learning purposes.
  • Oracle is an enterprise database management system product of Oracle. Oracle Database is considered one of the most sophisticated object-relational database management systems. And you can download and install the Oracle Database from Oracle’s website for educational purposes.

And there are more databases such as PostgreSQL, MariaDB, IBM DB2, and Sybase, just name a few.

To help you get the most out of each SQL tutorial, we also provide you with a SQL sample database so you can download and load it into your database management system. The sample database is available in MySQL and Microsoft SQL Server.

Section 1. Selecting data

  • SELECT– learn how to select data from a single table using the SELECT statement.
  • WHERE – show you how to use the WHERE clause to select data that match one or more conditions.
  • DISTINCT – show you how to select unique values from one or more columns in a table.
  • ORDER BY– show you how to sort the rows in the result set returned by the SELECT statement
  • Alias – use an alias to assign the column or expression a new name.

Section 2. SQL Operators

  • IN – leanr how to use the IN opeator to select value in a set of values
  • IS NULL – learn how to use the IS NULL operator to match NULL.
  • BETWEEN – use the BETWEEN operator to check if a value is in a range of value.
  • LIKE – show you how to match data based on a pattern.
  • EXISTS – learn how to use the EXISTS operator.

Section 3. Modifying data

  • INSERT – learn how to insert one or more rows into a table.
  • UPDATE – show you how to update existing data in a table.
  • DELETE – guide you on how to delete data from a table.
  • TRUNCATE TABLE – show you how to truncate data from a table.

Section 4. Advanced SQL

Provides advanced data selection techniques that involve multiple tables with complex conditions. In addition, we will also discuss the common SQL constraints that help you enforce data integrity automatically at the database layer:

  • GROUP BY – learn how to group data.
  • HAVING – show you how to filter the groups.
  • INNER JOIN – learn how to join data from two or more tables.
  • OUTER JOIN
  • Self Join – show you how to join a table with itself.
  • Subquery – learn how to nest a query within another query.
  • Correlated Subquery – explain the correlated subquery concept and show you how to apply the subqueries more effectively.

Section 5. Set operators

  • UNION – learn how to combine data from two or more tables.

Section 6. Working with database objects

SQL database definition language allows you to create, change or remove various kinds of database objects such as tables, views, indexes.

  • CREATE DATABASE – show you how to create a new database in the database server.
  • DROP DATABASE – learn how to completely remove a database.

Section 7. Working with tables

  • CREATE TABLE – learn how to create a new table.
  • ALTER TABLE – show you how to modify the structure of an existing table.
  • DROP TABLE – guide you on how to delete a table completely.

Section 8. SQL constraints

  • PRIMARY KEY – learn how to define the primary key for a table.
  • FOREIGN KEY – show you how to define foreign key constraints for a table.
  • UNIQUE – learn how to use the UNIQUE constraint to force the uniqueness of value in a table.
  • CHECK – learn how to validate data before insert or update.
  • DEFAULT – show you how to specify the default value for a column.
  • NOT NULL – show you how to use NOT NULL to enforce values in a column.

Section 9. SQL References

  • SQL Cheat Sheet – if you want to have a quick reference of SQL statements, you can download our printable.