Select (SQL): Difference between revisions

Content deleted Content added
mNo edit summary
m Use e.g. lower case "select"? Depending for first letter?
Line 1:
The [[SQL]] '''SELECT''' statement returns a [[result set]] of records, 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 |accessdate= |author=Microsoft }}</ref><ref>{{cite web |url=http://dev.mysql.com/doc/refman/5.0/en/select.html|title=SQL SELECT Syntax |accessdate= |author=MySQL}}</ref>
 
A '''SELECT''' statement retrieves zero or more rows from one or more [[Database Tables|database tables]] or database [[View (database)|views]]. In most applications, <code>SELECT</code> is the most commonly used [[data manipulation language]] (DML) command. As SQL is a [[declarative programming]] language, <code>SELECT</code> queries specify a result set, but do not 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 316:
|-
|
<syntaxhighlight lang="tsql">selectSelect TOP {begin_base_0 + rows}
*, _offset=identity(10)
into #temp
Line 339:
<syntaxhighlight lang="tsql">select TOP {rows} *
from (
select *, ROW_NUMBER() over (order by {unique_key}) as _offset
from {table}
) xx
Line 400:
<syntaxhighlight lang="tsql">select *
from (
Selectselect *
from {table}
where {unique_key} < {first_val}