You can use the SELECT
statement to query data from one or more tables and perform operations, such as filtering, grouping, and sorting, based on your business requirements.
[ WITH with_query [, ...] ]
SELECT
[ ALL | DISTINCT ] select_expr [, ...]
[ FROM table_reference [, ...] ]
[ WHERE condition ]
[ GROUP BY [ ALL | DISTINCT ] grouping_element [, ...] ]
[ HAVING condition]
[ WINDOW window_name AS (window_spec) [, window_name AS (window_spec)] ...]
[ { UNION | INTERSECT | EXCEPT } [ ALL | DISTINCT ] select ]
[ ORDER BY {column_name | expr | position} [ASC | DESC], ... [WITH ROLLUP]]
[LIMIT {[offset,] row_count | row_count OFFSET offset}]
table_reference
: the data source from which you want to query data. The source can be a table, a view, an associated table, or a subquery.Table names and column names are case-insensitive.
If a table name or a column name contains keywords or spaces, you can enclose the table name or the column name by using backticks (``).
WHERE
You can enter a BOOLEAN
expression in the WHERE
clause to query the data that meets the conditions. For example, execute the following statement to query the information about the customer whose customer_id
is 2368
:
SELECT * FROM CUSTOMER where customer_id=2368;
ALL and DISTINCT
You can use the ALL and DISTINCT keywords to specify whether duplicate rows are returned in the query result. The default value is ALL, which specifies that all rows are returned. The DISTINCT keyword specifies that duplicate rows are deleted from the query result.
SELECT id FROM orders;
SELECT DISTINCT id FROM orders;
You can click the following links to obtain information about other keywords in the SELECT statement: