Updated on 2022-11-18 GMT+08:00

SELECT

Syntax

[ WITH with_query [, ...] ]

SELECT [ ALL | DISTINCT ] select_expression [, ...]

[ FROM from_item [, ...] ]

[ [INNER | LEFT [OUTER|SEMI|ANTI] | RIGHT [OUTER|SEMI|ANTI] | FULL [OUTER] | CROSS]

JOIN table_reference

[ON join_equality_clauses | USING (col1[, col2 ...]] ...

[ WHERE condition ]

[ GROUP BY [ ALL | DISTINCT ] grouping_element [, ...] ]

[ HAVING condition]

[ { UNION | INTERSECT | EXCEPT } [ ALL | DISTINCT ] select ]

[ ORDER BY expression [ ASC | DESC ] [, ...] ]

[ OFFSET count [ ROW | ROWS ] ]

[ LIMIT { count | ALL } ]

[ FETCH { FIRST | NEXT } [ count ] { ROW | ROWS } { ONLY | WITH TIES } ]

  • The value of from_item can be:

    table_name [ [ AS ] alias [ ( column_alias [, ...] ) ] ]

    from_item join_type from_item [ ON join_condition | USING ( join_column [, ...] ) ]

  • join_type can be:

    [ INNER ] JOIN

    LEFT [ OUTER ] JOIN

    RIGHT [ OUTER ] JOIN

    FULL [ OUTER ] JOIN

    LEFT [SEMI] JOIN

    RIGHT [SEMI] JOIN

    LEFT [ANTI] JOIN

    RIGHT [ANTI] JOIN

    CROSS JOIN

  • grouping_element can be:

    ()

    expression

    GROUPING SETS ( ( column [, ...] ) [, ...] )

    CUBE ( column [, ...] )

    ROLLUP ( column [, ...] )

Description

This statement is used to retrieve row data from zero or more tables.

Query the content of the stu table.

SELECT id,name FROM stu;