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

CC BY-NC-ND International 4.0

CC BY-NC-ND International 4.0: This work is released under a CC BY-NC-ND International 4.0 license, which means that you are free to do with it as you please as long as you (1) properly attribute it, (2) do not use it for commercial gain, and (3) do not create derivative works.

End-of-Chapter Survey

: How would you rate the overall quality of this chapter?
  1. Very Low Quality
  2. Low Quality
  3. Moderate Quality
  4. High Quality
  5. Very High Quality
Comments will be automatically submitted when you navigate away from the page.
Like this? Endorse it!