語法
更新時間:
SELECT
語句用于從一個或多個表中查詢數據,并根據需要進行過濾、分組、排序等操作。
[ 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
:查詢的數據源,可以是表、視圖、關聯表或者子查詢。表名和列名不區分大小寫。
表名和列名中如果含有關鍵字或者空格等字符,可以使用反引號(``)將其引起來。
WHERE
WHERE
關鍵字后跟BOOLEAN
表達式,用于從表中查詢滿足條件的數據。例如,在CUSTOMER表中查詢customer_id
為2368
的顧客信息。
SELECT * FROM CUSTOMER where customer_id=2368;
ALL和DISTINCT
ALL和DISTINCT關鍵字用于指定查詢結果是否返回重復的行,默認值為ALL,即返回所有匹配的行,DISTINCT將從結果集中刪除重復的行。
SELECT id FROM orders;
SELECT DISTINCT id FROM orders;
以下為SELECT中的其他關鍵字用法。
文檔內容是否對您有幫助?