Select (SQL): Difference between revisions

Content deleted Content added
Query evaluation ANSI: g.GroupName, count(g.*) as NumberOfMembers from users u inner join groups g on g.Userid = u.Userid group by GroupName having count(g.*) > 5 </syntaxhighlight> |8= the SELECT list is evaluated and returned as Vtable 7 |9= the DISTINCT clause is evaluated; duplicate rows are removed and returned as Vtable 8 |10= the ORDER BY clause is evaluated, ordering the rows and returning VCursor9. This is a cursor and not a table because ANSI defines a cursor as an ordered set...
Tags: Reverted Mobile edit Mobile web edit
m Reverted edits by 49.237.41.22 (talk) (AV)
Line 1:
{{Short description|SQL statement that returns a result set of rows from one or more tables}}
The [[SQL]] '''SELECT''' statement returns a [[result set]] of rows, from one or more [[Table (database)|tables]].<ref>{{cite web |url=http://msdn2.microsoft.com/en-us/library/ms189499.aspx |title=Transact-SQL Syntax Conventions |author=Microsoft |date=23 May 2023 }}</ref><ref>{{cite web |url=http://dev.mysql.com/doc/refman/5.0/en/select.html|title=SQL SELECT Syntax |author=MySQL}}</ref>
The [[SQL]] '''SELECT''' statement returns a [[result set]] of rows, from one or specify how to calculate it. The database translates the query into a "[[query plan]]" which may vary between executions, database versions and database software. This functionality is called the "[[query optimizer]]" as it is responsible for finding the best possible execution plan for the query, within applicable constraints.
 
TheA SELECT statement retrieves zero or more rows from one or more [[SQLDatabase Tables|database tables]] '''or database [[View (database)|views]]. In most applications, <code>SELECT'''</code> statementis the most commonly used [[data manipulation language]] (DML) command. As SQL returnsis a [[resultdeclarative setprogramming]] oflanguage, rows<code>SELECT</code> queries specify a result set, frombut onedo ornot specify how to calculate it. The database translates the query into a "[[query plan]]" which may vary between executions, database versions and database software. This functionality is called the "[[query optimizer]]" as it is responsible for finding the best possible execution plan for the query, within applicable constraints.
 
The SELECT statement has many optional clauses:
Line 704 ⟶ 706:
|7= the HAVING clause is evaluated for groups for which the HAVING clause is true and inserted into vTable6. For example:
<syntaxhighlight lang="postgresql">
select g.GroupName, count(g.*) as NumberOfMembers
select relational).
from users u inner join groups g on g.Userid = u.Userid
group by GroupName
having count(g.*) > 5
</syntaxhighlight>
|8= the SELECT list is evaluated and returned as Vtable 7
|9= the DISTINCT clause is evaluated; duplicate rows are removed and returned as Vtable 8
|10= the ORDER BY clause is evaluated, ordering the rows and returning VCursor9. This is a cursor and not a table because ANSI defines a cursor as an ordered set of rows (not relational).
}}