Logo 
Search:

SQL Server Articles

Submit Article
Home » Articles » SQL Server » Select QueryRSS Feeds

Retrieving Columns with SELECT and FROM

Posted By: Sarita Patel     Category: SQL Server     Views: 2907

This article explains significance of select and from clause to retrieve column, multiple columns and all columns from a table.

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.

 

  
Share: 


Didn't find what you were looking for? Find more on Retrieving Columns with SELECT and FROM Or get search suggestion and latest updates.

Sarita Patel
Sarita Patel author of Retrieving Columns with SELECT and FROM is from United States.
 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!