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!
== Examples == {| class="wikitable" style="float: right; clear:right; margin: 1em" border="1" !Table "T" !Query !Result |- |align="center"| {| cellpadding="2" rules="all" style="border: 1px solid gray; text-align: center;" ! C1 !! C2 |- | 1 || a |- | 2 || b |} ||{{code|2=sql|1=SELECT * FROM T;}} |align="center"| {| cellpadding="2" rules="all" style="border: 1px solid gray; text-align: center;" ! C1 !! C2 |- | 1 || a |- | 2 || b |} |- |align="center"| {| cellpadding="2" rules="all" style="border: 1px solid gray; text-align: center;" ! C1 !! C2 |- | 1 || a |- | 2 || b |} ||{{code|2=sql|1=SELECT C1 FROM T;}} |align="center"| {| cellpadding="2" rules="all" style="border: 1px solid gray; text-align: center;" ! C1 |- | 1 |- | 2 |} |- |align="center"| {| cellpadding="2" rules="all" style="border: 1px solid gray; text-align: center;" ! C1 !! C2 |- | 1 || a |- | 2 || b |} ||{{code|2=sql|1=SELECT * FROM T WHERE C1 = 1;}} |align="center"| {| cellpadding="2" rules="all" style="border: 1px solid gray; text-align: center;" ! C1 !! C2 |- | 1 || a |} |- |align="center"| {| cellpadding="2" rules="all" style="border: 1px solid gray; text-align: center;" ! C1 !! C2 |- | 1 || a |- | 2 || b |} ||{{code|2=sql|1=SELECT * FROM T ORDER BY C1 DESC;}} |align="center"| {| cellpadding="2" rules="all" style="border: 1px solid gray; text-align: center;" ! C1 !! C2 |- | 2 || b |- | 1 || a |} |- |align="center"|does not exist ||{{code|2=sql|1=SELECT 1+1, 3*2;}} |align="center"| {| cellpadding="2" rules="all" style="border: 1px solid gray; text-align: center;" ! `1+1` !! `3*2` |- | 2 || 6 |} |} 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 [[relational 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 [[relational 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. Although not in standard, most DBMS allows using a select clause without a table by pretending that an imaginary table with one row is used. This is mainly used to perform calculations where a table is not needed. The SELECT clause specifies a list of properties (columns) by name, or the wildcard character (“*”) to mean “all properties”.
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)