• Learning MySQL By Example
  • Introduction
  • 1. How to Retrieve Data From a Single Table
  • 2. How to Retrieve Data from Multiple Tables
  • 3. Using Functions
  • 4. How to Insert, Update, Delete Data in Tables
  • 5. Summary Queries and Aggregate Functions
  • 6. Working With Subqueries
  • 7. SQL Views
  • 8. SQL Indexes
  • Glossary
  • Index
  • Download
  • Translations
  • 1.1

    The Five Clauses of the SELECT Statement

    The Five Clauses of the SELECT statement

    • SELECT – the columns in the result set
    • FROM – names the base table(s) from which results will be retrieved
    • WHERE – specifies any conditions for the results set (filter)
    • ORDER BY – sets how the result set will be ordered
    • LIMIT – sets the number of rows to be returned

    The clauses MUST appear in the order shown above.

    Code Example:1    USE world;
    2    SELECT name
    3    FROM city
    4    WHERE CountryCode = “AFG”
    5    ORDER BY name
    6    LIMIT 3

    Results:

    Retrieve_data_from_a_single_table_example1.png

    Let us break the statement line by line:

    USE world;

    SELECT name

    FROM city

    ORDER BY name

    LIMIT 5;

    Table 1. Column Specifications

    Source Option Syntax

    Base Table Value

    Show all columns

     

    Base Table Value

    Column Name

    Comma-separated list of column names

    Calculated Value

    Calculation result

    Arithmetic expression

    Calculated Value

    Calculation result

    Functions

    This content is provided to you freely by EdTech Books.

    Access it online or download it at https://edtechbooks.org/learning_mysql/the_five_clauses_of_.