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.
| EmployeeID | NationalIDNumber | Title | ManagerID |
|---|---|---|---|
| 1 | 14417807 | Production Technician - WC60 | 16 |
| 2 | 253022876 | Marketing Assistant | 6 |
| 3 | 509647174 | Engineering Manager | 12 |
| 4 | 112457891 | Senior Tool Designer | 3 |
| 5 | 480168528 | Tool Designer | 263 |
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 }
