Sunteți pe pagina 1din 1

SELECT Name SELECT -- retrieve rows from a table or view Synopsis SELECT [ ALL | DISTINCT [ ON ( expression [, ...

] ) ] ] * | expression [ AS output_name ] [, ...] [ FROM from_item [, ...] ] [ WHERE condition ] [ GROUP BY expression [, ...] ] [ HAVING condition [, ...] ] [ { UNION | INTERSECT | EXCEPT } [ ALL ] select ] [ ORDER BY expression [ ASC | DESC | USING operator ] [, ...] ] [ LIMIT { count | ALL } ] [ OFFSET start ] [ FOR { UPDATE | SHARE } [ OF table_name [, ...] ] [ NOWAIT ] ] where from_item can be one of: [ ONLY ] table_name [ * ] [ [ AS ] alias [ ( column_alias [, ...] ) ] ] ( select ) [ AS ] alias [ ( column_alias [, ...] ) ] function_name ( [ argument [, ...] ] ) [ AS ] alias [ ( column_alias [, ...] | column_definition [, ...] ) ] function_name ( [ argument [, ...] ] ) AS ( column_definition [, ...] ) from_item [ NATURAL ] join_type from_item [ ON join_condition | USING ( join _column [, ...] ) ] Description SELECT retrieves rows from zero or more tables. The general processing of SELECT is as follows: 1. All elements in the FROM list are computed. (Each element in the FROM li st is a real or virtual table.) If more than one element is specified in the FRO M list, they are cross-joined together. (See FROM Clause below.) 2. If the WHERE clause is specified, all rows that do not satisfy the condi tion are eliminated from the output. (See WHERE Clause below.) 3. If the GROUP BY clause is specified, the output is divided into groups o f rows that match on one or more values. If the HAVING clause is present, it eli minates groups that do not satisfy the given condition. (See GROUP BY Clause and HAVING Clause below.) 4. The actual output rows are computed using the SELECT output expressions for each selected row. (See SELECT List below.) 5. Using the operators UNION, INTERSECT, and EXCEPT, the output of more tha n one SELECT statement can be combined to form a single result set. The UNION op erator returns all rows that are in one or both of the result sets. The INTERSEC T operator returns all rows that are strictly in both result sets. The EXCEPT op erator returns the rows that are in the first result set but not in the second. In all three cases, duplicate rows are eliminated unless ALL is specified. (See UNION Clause, INTERSECT Clause, and EXCEPT Clause below.) 6. If the ORDER BY clause is specified, the returned rows are sorted in the specified order. If ORDER BY is not given, the rows are returned in whatever or der the system finds fastest to produce. (See ORDER BY Clause below.) 7. DISTINCT eliminates duplicate rows from the result. DISTINCT ON eliminat es rows that match on all the specified expressions. ALL (the default) will retu rn all candidate rows, including duplicates. (See DISTINCT Clause below.) 8. If the LIMIT or OFFSET clause is specified, the SELECT statement only re turns a subset of the result rows. (See LIMIT Clause below.) 9. If the FOR UPDATE or FOR SHARE clause is specified, the SELECT statement locks the selected rows against concurrent updates. (See FOR UPDATE/FOR SHARE C lause below.) You must have SELECT privilege on a table to read its values. The use of FOR UPD ATE or FOR SHARE requires UPDATE privilege as well.

S-ar putea să vă placă și