Simplest use of SELECT statement is to retrieve one column,
multiple column or all columns . The SELECT clause lists the columns to
display, and the FROM cluase specifies the table from which columns will be
displayed.
If you retrieve columns from tables, SELECT and FROM clauses are
required, all other clauses are optional.
Syntax of SELECT clause :
SELECT [ ALL | DISTINCT ] [ TOP expression [ PERCENT ] [ WITH TIES ] ]
{ * | { table_name | view_name | alias_name }.* | { column_name | [ ] expression | $IDENTITY | $ROWGUID } [ [ AS ] column_alias ] | column_alias = expression } [ ,...n ]
FROM table_name | view_na me alias_name
WHERE filter_criteria
ORDERBY ordering_criteria
To retrieve a column from a table :
Syntax of SELECT clause to get a column from a table
SELECT column
FROM table
Example of SELECT clause to get a column from a table
SELECT ContactName
FROM Customers
Output
ContactName
Maria Anders
Ana Trujillo
Antonio Moreno
Thomas Hardy
Christina Berglund
Hanna Moos
Above query dispays
all ContactName column values from Customers table.
To retrieve multiple columns from a table :
Syntax of SELECT clause to get multiple column from a table
SELECT column1,column2….
FROM table
Example of SELECT clause to get multiple column from a table
SELECT ContactName, CompanyName
FROM Customers
Output
ContactName CompanyName
Maria Anders Alfreds
Futterkiste
Ana Trujillo
Ana Trujillo Emparedados y
helados
Antonio Moreno Antonio Moreno Taquería
Thomas Hardy Around the Horn
Christina Berglund Berglunds snabbköp
Hanna Moos Blauer See Delikatessen
Above query dispays all ContactName and CompanyName column
values from Customers table.
To retrieve all columns from a table :
Syntax of SELECT clause to get all columns from a table :
SELECT *
FROM table
Example of SELECT clause to get all columns from a table :
SELECT *
FROM Region
Output
RegionID RegionDescription
1 Eastern
2 Western
3 Northern
4 Southern
Above query returns all column values of region table.