Sunday, 10 February 2013

SQL SELECT Statement Syntax and Examples

SQL SELECT Statement
The SELECT statement is used to select data from a Database Table.The result is stored in a result table, called the result-set.

Syntax :
SELECT column_name(s)FROM table_name
and
SELECT * FROM table_name

Remainder: SQL is not case sensitive. SELECT is the same as select.

Selecting Specific Columns Example:
The "ORDERS" table:
Order_Id
Sales_Period
Cust_Id
Sales
ABC_1234
Q1-2014
Cust_1234
40474
BCD_2345
Q2-2014
Cust_2345
44321
CDE_3456
Q3-2014
Cust_3456
19906
DEF_4567
Q4-2014
Cust_4567
34943
EFG_1122
Q1-2015
Cust_1122
22114
FGH_3344
Q2-2015
Cust_3344
41364
GHI_5566
Q3-2015
Cust_5566
16157
IJK_7788
Q4-2015
Cust_7788
36054


Now we want to select the some of the columns named "Order_Id" and "Sales" from the table above.We use the following SELECT statement:
SELECT Order_Id,Sales From ORDERS

The result-set will look like as below:
Order_Id
Sales
ABC_1234
40474
BCD_2345
44321
CDE_3456
19906
DEF_4567
34943
EFG_1122
22114
FGH_3344
41364
GHI_5566
16157
IJK_7788
36054

SELECT * Example :
Now we want to select all the columns from the "ORDERS" table.We use the following SELECT statement: 
SELECT * From ORDERS
Hint: The asterisk (*) is a quick way of selecting all columns!

The result-set will look like as below:
Order_Id
Sales_Period
Cust_Id
Sales
ABC_1234
Q1-2014
Cust_1234
40474
BCD_2345
Q2-2014
Cust_2345
44321
CDE_3456
Q3-2014
Cust_3456
19906
DEF_4567
Q4-2014
Cust_4567
34943
EFG_1122
Q1-2015
Cust_1122
22114
FGH_3344
Q2-2015
Cust_3344
41364
GHI_5566
Q3-2015
Cust_5566
16157
IJK_7788
Q4-2015
Cust_7788
36054


Thanks,
TAMATAM

No comments:

Post a Comment

Follow Me by Email

ExcelKingdom-Popular Posts

ExcelKingdom-Random Posts