Skip to main content
Version: 1.0.16

SQL Introduction

SQL is a language for querying and manipulating relational database management systems. It is a concrete implementation of relational algebra (though it may not include all operations from relational algebra). SQL consists of two main parts:

  • Data Definition Language (DDL), used to define database structures and data access control.

  • Data Manipulation Language (DML), used to retrieve and update data.

SQL is a non-procedural language. Users only need to describe the information they need without providing the specific process for obtaining that information, meaning SQL does not require specifying data access methods.

Simple SQL Query Example

The simplest query in SQL is to find tuples in a relation that satisfy specific conditions. Simple queries use three reserved keywords that characterize SQL: SELECT, FROM, and WHERE. For example, to find the weather information for Hangzhou on 2020-07-01 from the weather relation, the SQL statement is:

SELECT * FROM weather
WHERE city = '杭州' AND date = DATE '2020-07-01';

This query demonstrates the typical format of most SQL query statements, namely the select-from-where form.

  • The FROM clause specifies the relation referenced by the query. In this example, the relation referenced by the query is weather.

  • The WHERE clause is a conditional clause, similar to the selection condition in relational algebra. Tuples that match the query must satisfy this condition. In this example, the conditions are on the city attribute (value '杭州') and the date attribute (value DATE '2020-07-01') of the tuple.

  • The SELECT clause determines which attributes of the tuples satisfying the condition should be listed in the result. The * in the example indicates that all attributes of the tuple should be listed.

To learn more about the SQL language, we recommend reading "Database in Depth".