SQL SELECT statement is used to retrieve records from the database. The SQL Select statement returns the records according to the parameters or expressions used to filter and arrangement of the records specified by the SQL query. A select item may be:
SELECT [ALL | DISTINCT] [TOP n {PERCENT}] [COLUMN_NAME {as ‘column alias’} | *] FROM [TABLE_NAME] WHERE {CONDITION} ORDER BY [column name] [ASC | DESC]
ALL keyword is used to allow the SELECT statement to return duplicate records.
DISTINCT keyword specifies to retrieve the unique records only.
TOP n {PERCENT} returns first n rows. E.g. Top 10 returns first 10 rows only. TOP n PERCENT returns first n percent rows.
COLUMN_NAME: you can specify column names separated by comma to retrieve the data only from the specified columns.
* Symbol is used to retrieve the data from all the columns of table.
FROM clause is used to specify the table name after FROM. This clause specifies the table name for which the data is being requested.
Column alias defines a new name for the column where alias is specified, it replaces the original name of the column e.g. Select fname as ‘First Name’ from employee
WHERE: clause can be used to set any condition for retrieving only specific records e.g.
Select fname from employee WHERE fname=’Paul’
ORDER BY keyword is used to retrieve the records in a specific manner. ORDER BY is mapped with any column according to which sorting takes place. You can arrange the result is ascending or descending order by using ASC for ascending and DESC for descending order e.g.
Select fname from employee ORDER BY fname DESC
Example of SQL SELECT Statement
SELECT TOP 10 fname as ‘First Name’ FROM employee ORDER BY fname DESC
Or
SELECT * FROM employee WHERE fname=’Paul’
Don't know what does SQL stand for? then click here...
Be the first to rate this post
Tags: sql, sql free tutorial, sql select statement
8/23/2008 8:43:35 PM