What do we use SQL commands for?
A common use is to select data from the tables located in a database. Immediately, we see two keywords: we need to SELECT information FROM a table.
we have the most basic SQL query structure:
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_Name | Sales | Txn_Date |
Los Angeles | 1500 | Jan-05-1999 |
San Diego | 250 | Jan-07-1999 |
Los Angeles | 300 | Jan-08-1999 |
Boston | 700 | Jan-08-1999 |
Select One Column
To select a single column, we specify the column name between SELECT and FROM as follows:
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:
Result:
Select All Columns
Store_Name | Sales |
Los Angeles | 1500 |
San Diego | 250 |
Los Angeles | 300 |
Boston | 700 |
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 from Store_Information, we issue the following SQL:
Result:
Los Angeles 1500 Jan-05-1999
San Diego 250 Jan-07-1999
Los Angeles 300 Jan-08-1999
Boston 700 Jan-08-1999
No comments:
Post a Comment