×
Menu
Index

SQL Command SELECT

 
The SELECT command has the following specification:
 
SELECT * | field1 [, field2 ] ... [, fieldN ]
FROM TableName
[WHERE logical_expression]
[ORDER BY orderField1 [ ASC | DESC ], [ orderField2 [ ASC | DESC ] ] , … , [ orderFieldM [ ASC | DESC ] ] ]
 
where:
 
* - all the fields in the table will be returned.
field1, field2,…, fieldN – the fields listed will be returned from the command in the order specified in list.
At least one form of the two above must be used in order for the command to be carried out.
 
TableName – specify the name of the table for which the command is applied.
 
logical_expression – identify the rows that will appear in result
 
orderField1, orderField2,..., orderFieldM – identify the columns which will be used to sort the result set.
 
A column can be specified as a name or a non-negative integer (1 – n) representing the position of the name in the select list.
All column names must appear in the select list. The sequence of the sort columns defines the organization of the sorted result set.
 
Each sort column may have one of the following attributes:
ASC - The values in the specified column will be sorted in ascending order, from lowest value to highest value.
DESC - The values in the specified column will be sorted in descending order, from highest value to lowest value.
When none of these attributes is specified, the sort will be performed as ASC.
 
Examples
select * from params
select name, value from params
select value from params where name="AppDownload"
select * from params where value="0" OR value="1"
select * from params order by name
select * from params order by name ASC
select * from params order by name DESC