Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Select (SQL)
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Query evaluation ANSI == The processing of a SELECT statement according to ANSI SQL would be the following:<ref>Inside Microsoft SQL Server 2005: T-SQL Querying by Itzik Ben-Gan, Lubor Kollar, and Dejan Sarka</ref> {{ordered list |1=<syntaxhighlight lang="postgresql"> select g.* from users u inner join groups g on g.Userid = u.Userid where u.LastName = 'Smith' and u.FirstName = 'John' </syntaxhighlight> |2= the FROM clause is evaluated, a cross join or Cartesian product is produced for the first two tables in the FROM clause resulting in a virtual table as Vtable1 |3= the ON clause is evaluated for vtable1; only records which meet the join condition g.Userid = u.Userid are inserted into Vtable2 |4= If an outer join is specified, records which were dropped from vTable2 are added into VTable 3, for instance if the above query were: <syntaxhighlight lang="postgresql"> select u.* from users u left join groups g on g.Userid = u.Userid where u.LastName = 'Smith' and u.FirstName = 'John' </syntaxhighlight> all users who did not belong to any groups would be added back into Vtable3 |5= the WHERE clause is evaluated, in this case only group information for user John Smith would be added to vTable4 |6= the GROUP BY is evaluated; if the above query were: <syntaxhighlight lang="postgresql"> select g.GroupName, count(g.*) as NumberOfMembers from users u inner join groups g on g.Userid = u.Userid group by GroupName </syntaxhighlight> vTable5 would consist of members returned from vTable4 arranged by the grouping, in this case the GroupName |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 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). }}
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)