Monday 18 June 2012

Lesson 6: Retrieving Multiple Columns in SQL


You can use SQL to retrieve multiple columns.


Syntax:
Select fieldname, fieldname, fieldname
from tablename;


Explanation:
  • When retrieving multiple columns, specify each field name. 
  • A comma must separate field names. 
  • The columns will display in the order you select them. 
  • Numbers display in scientific notation.
Example:Retrieve the vendor ID, name, and current balance for each record:
  1. In the SQL text box, type:
Select VendId, Name, CurrBal
from TrnVendor; 
  1. Execute the command by clicking on First, the Run button located to the right of the SQL text box. The results will display on the screen.
  2. Use the vertical scroll bar to move up and down the screen.
  3. Click on Stop to return to the original screen
Results:
 
VendIdNameCurrBal
TV001Wet Off Towels1.31300E+001
TV002The Games All Here4.53170E+002
TV003BedMakers Linen5.00000E+002
TV004Bed Room Furniture, Inc.3.21700E+002
TV005Ray Block1.00123E+003
TV006Mosquito No Bite9.67240E+002
TV007Spot Out1.60654E+003

No comments:

Post a Comment