SQL SELECT Statement

by top54u.com 01 Nov, 2007
Spotlight.....

 

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:

  • A column name: SQL select statement takes column name as an argument that in turn returns the rows having values retrieved from the given column name from the specified table.

  • Any aggregate function applied on column that calculates the value according to the function used. A constant value can also be used to display in each row.

  • Any calculative SQL expression applied on couple of columns that returns the result of expression in the retrieved results in the form of column. Column alias can be used to define that column result.

 

 

SQL Select Statement Syntax

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...

Spotlight.....

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , ,

Add comment


(Will show your Gravatar icon)  

  Country flag

[b][/b] - [i][/i] - [u][/u]- [quote][/quote]



Live preview

8/23/2008 8:43:35 PM

OUR SPONSORS[+ advertise here]
related videos.....
recent posts.....
top54u ezines.....