Name
SELECT
Synopsis
SELECT [flags] {column, . . . |expressions}[, . . . ] FROMtable[, . . . ] [WHEREcondition] [GROUP BY {column|expression|position}[ASC|DESC], . . . [WITH ROLLUP]] [HAVINGcondition] [ORDER BY {column|expression|position}[ASC|DESC] , . . . ] [LIMIT {[offset,]count|countOFFSEToffset}] [PROCEDUREprocedure(arguments)]options
Use this
statement to retrieve and display data from tables within a database.
It has many clauses and options. However, for simple data retrieval
many of them can be omitted. The basic syntax for the statement is
shown. After the SELECT keyword, some flags may be
given. Next, a list of columns to retrieve and/or expressions may be
given, separated by commas. For the tables, all that is required is
one or more table names from which to retrieve data in a
comma-separated list. The remaining clauses may be called on to
refine the data to be retrieved, to order it, and so forth. These
various flags, options, and clauses are detailed in subsections to
this statement explanation. Here is a simple example of how you can
use this statement:
SELECT name_first, name_last, telephone_home,
DATEDIFF(now( ), last_review)
AS 'Days Since Last Review'
FROM employees;In this example, three columns and the results of an expression based on a fourth column are to be displayed. The first and last name of each employee, each employee's home telephone number, and the difference between the date of the employee's last employment review and the date now are listed. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access