Select (SQL): Difference between revisions

Content deleted Content added
m Use e.g. lower case "select"? Depending for first letter?
mNo edit summary
Line 99:
Given a table T, the ''query'' {{code|2=sql|1=SELECT * FROM T}} will result in all the elements of all the rows of the table being shown.
 
With the same table, the query {{code|2=sql|1=SELECT C1 FROM T}} will result in the elements from the column C1 of all the rows of the table being shown. This is similar to a ''[[Projection (relational algebra)|projection]]'' in [[Relationalrelational algebra]], except that in the general case, the result may contain duplicate rows. This is also known as a Vertical Partition in some database terms, restricting query output to view only specified fields or columns.
 
With the same table, the query {{code|2=sql|1=SELECT * FROM T WHERE C1 = 1}} will result in all the elements of all the rows where the value of column C1 is '1' being shown —{{snd}} in [[Relationalrelational algebra]] terms, a ''[[Selection (relational algebra)|selection]]'' will be performed, because of the WHERE clause. This is also known as a Horizontal Partition, restricting rows output by a query according to specified conditions.
 
With more than one table, the result set will be every combination of rows. So if two tables are T1 and T2, {{code|2=sql|1=SELECT * FROM T1, T2}} will result in every combination of T1 rows with every T2 rows. E.g., if T1 has 3 rows and T2 has 5 rows, then 15 rows will result.
Line 250:
order by {unique_key}
FETCH FIRST {begin_base_0 + rows} ROWS ONLY</syntaxhighlight>
| SQL ANSI 2008<br>PostgresqlPostgreSQL<br>SQL Server 2012<br>Derby<br>Oracle 12c<br>DB2 12
|-
|
Line 299:
OFFSET {begin_base_0} ROWS
FETCH NEXT {rows} ROWS ONLY</syntaxhighlight>
| SQL ANSI 2008<br>PostgresqlPostgreSQL<br>SQL Server 2012<br>Derby<br>Oracle 12c<br>DB2 12
|-
|
Line 306:
order by {unique_key}
LIMIT {rows} OFFSET {begin_base_0}</syntaxhighlight>
| MySQL<br>MariaDB<br>PostgresqlPostgreSQL<br>SQLite
|-
|
Line 407:
) a
order by {unique_key}</syntaxhighlight>
| SQL ANSI 2008<br>PostgresqlPostgreSQL<br>SQL Server 2012<br>Derby<br>Oracle 12c<br>DB2 12
|-
|
Line 597:
== External links ==
* [http://wwwlgis.informatik.uni-kl.de/cms/fileadmin/courses/SS2008/NEDM/RDDM.Chapter.06.Windows_and_Query_Functions_in_SQL.pdf Windowed Tables and Window function in SQL], Stefan Deßloch
* [httphttps://download.oracle.com/docs/cd/B14117_01/server.101/b10759/statements_10002.htm Oracle SELECT Syntax.syntax]
* [httphttps://www.firebirdsql.org/rlsnotesh/rlsnotes210.html#rnfb20x-dml-select-syntax Firebird SELECT Syntax.syntax]
* [httphttps://dev.mysql.com/doc/refman/58.10/en/select.html MysqlMySQL SELECT Syntax.syntax]
* [httphttps://www.postgresql.org/docs/current/static/sql-select.html PostgresPostgreSQL SELECT Syntax.syntax]
* [httphttps://www.sqlite.org/lang_select.html SQLite SELECT Syntax.syntax]
 
{{SQL}}