Retrieving Multiple Columns

To retrieve multiple columns from a table, the same SELECT statement is used. The only difference is that multiple column names must be specified after the SELECT keyword, and each column must be separated by a comma.

Caution

Take Care with Commas When selecting multiple columns be sure to specify a comma between each column name, but not after the last column name. Doing so will generate an error.


The following SELECT statement retrieves three columns from the products table:

SELECT prod_id, prod_name, prod_price
FROM Products;

Just as in the prior example, this statement uses the SELECT statement to retrieve data from the products table. In this example, three column names are specified, each separated by a comma. The output from this statement is shown below:

prod_id     prod_name               prod_price
---------  --------------------  ----------
BNBG01      Fish bean bag toy       3.4900
BNBG02      Bird bean bag toy       3.4900
BNBG03      Rabbit bean bag toy     3.4900
BR01        8 inch teddy bear       5.9900
BR02        12 inch teddy bear      8.9900
BR03        18 inch teddy bear      11.9900
RGAN01      Raggedy Ann             4.9900

Note

Presentation of Data As you will notice in the above output, SQL statements typically return raw, unformatted data. Data formatting is a presentation issue, not a retrieval issue. Therefore, presentations (for example, displaying the above price values as currency amounts with the correct number of decimal places) are specified in the application that displays the data. Actual retrieved data (without application-provided formatting) is rarely used.


..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.138.67.203