The SQL SELECT Statement The SELECT statement is used to SELECT data from a table. The tabular result is stored in a result table (called the result-set).
Sample Basic Syntax
Select
ColumnName
From
TableName;
Note: Depending on your SQL installation statements can be case sensitive. By default SQL Server 2012 is case sensitive.
Write Exercise Code
SELECT Single Column
To SELECT the content of column named "ProductNumber", from the table called "Product", write a SELECT statement like this:
Select
ProductNumber
From
Product
In more common terms, this request could be similar to.
“Can you help me get a list of all product numbers from our Product table?” or even
“Can you help me get a list of all product numbers for our products?”
Because you have the context that all product information is located in the Products table, the person requesting the information may not know the details of the database.
SELECT Multiple Columns
To SELECT multiple columns from the "Product" table, type in column names. Remember to add comma after each column name:
Select
ProductNumber, Name
From
Product
Results In more common terms, this request could be similar to. “Can you help me get a list of all product names, and their numbers for our products?
SELECT All Columns
To SELECT all columns from the "Product" table, use a * symbol instead of column names, like this:
Select
*
From
Product
In more common terms, this request could be similar to.
“Can you help me get a list of all product information?”
In next part we will learn about select distinct with some query examples