SELECT


SELECT "column_name" FROM "table_name";
There are three ways we can retrieve data from a table:
  • Retrieve one column
  • Retrieve multiple columns
  • Retrieve all columns
Let's use the following table to illustrate all three cases:
Table Store_Information
Store_NameSalesTxn_Date
Los Angeles1500Jan-05-1999
San Diego250Jan-07-1999
Los Angeles300Jan-08-1999
Boston700Jan-08-1999

Select One Column

To select a single column, we specify the column name between SELECT and FROM as follows:
SELECT Store_Name FROM Store_Information;
Result:
Store_Name
Los Angeles
San Diego
Los Angeles
Boston

Select Multiple Columns

We can use the SELECT statement to retrieve more than one column. To select Store_Name and Sales columns from Store_Information, we use the following SQL:
SELECT Store_Name, Sales FROM Store_Information;
Result:
Store_NameSales
Los Angeles1500
San Diego250
Los Angeles300
Boston700

Select All Columns

There are two ways to select all columns from a table. The first is to list the column name of each column. The second, and the easier, way is to use the symbol *. For example, to select all columns fromStore_Information, we issue the following SQL:
SELECT * FROM Store_Information;
Result:
Store_NameSalesTxn_Date
Los Angeles1500Jan-05-1999
San Diego250Jan-07-1999
Los Angeles300Jan-08-1999
Boston700Jan-08-1999

No comments:

Post a Comment