SQL Select Statement

January 27, 2010

in SQL Basics

Out of all the statements in SQL (Structured Query Language), the Select statement is by far the most used once.

The select statement is used to retrieve data from tables/view/combination of tables and views in a database. The result thus generated using this statement is used for display to users through GUI, for reporting purpose, for processing the data and etc.

Such a result generated using a Select Statement is called a Result – Set.

The basic Syntax for a Select Statement is (One thing to be noted over he is SQL is not case sensitive)

SELECT Column_List FROM Table_Name

The <Table_Name> gets more prefixes depending on the Environment we have to select the data from, it can be also written as a three part identifies as [Database Name].[Schema Name].[Table Name]

Here is an example making use of the database AdventureWorks which is available from the site http://www.codeplex.com for download.

Use AdventureWorks
Go
SELECT EmployeeID,NationalIDNumber,Title,ManagerID FROM HumanResources.Employee

The above sql select statement selects four columns from the table Emplyee residing in the schema HumanResources.

EmployeeIDNationalIDNumberTitleManagerID
114417807Production Technician - WC6016
2253022876Marketing Assistant6
3509647174Engineering Manager12
4112457891Senior Tool Designer3
5480168528Tool Designer263

Now let us see one more basic example, say instead of a few columns we want to select all the columns in a table, for that we use the asterisk symbol “*”.
When we are going to write it, It’s going to take a form of the below

SELECT * FROM [Database Name].[Schema Name].[Table Name]

Here it is

Use AdventureWorks
Go
SELECT * FROM HumanResources.Employe

That’s it for not, will further write on these basics in the comin articles.
If you have like it and want to get the articles (or) new post at sql like, subscribe to articles through email by entering your email address in the top right and verifying the same.

 if you have any comments, then the below form is for you, go ahead!!!

Comments on this entry are closed.

Previous post:

Next post: