Database Articles

  Home arrow Database Articles arrow Page 3 - Databases and SQL
DATABASE ARTICLES

Databases and SQL
By: bluephoenix
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2004-04-19

    Table of Contents:
  • Databases and SQL
  • Adding Information To A Database
  • Retrieving Information From A Database
  • Changing Information In A Database
  • Conclusion

  •  
     

    SEARCH CODEWALKERS

    TOOLS YOU CAN USE

    advertisement

    Databases and SQL - Retrieving Information From A Database


    (Page 3 of 5 )

    It wouldn't make sense to save information without the ability to retrieve it at some future date. The SELECT command is used to retrieve records from a table.

    The SELECT statement is both powerful and flexible. But because this is an introductory tutorial, all of the nuances of the SELECT command won't be covered. I'll instead illustrate the basic usage of the command.

    A simple form of the SELECT command is SELECT followed by the desired field to retrieve, FROM and then followed by the desired table. An asterisk can be used as shorthand to request all fields.

    SELECT * FROM addresses;

    The results of such a query might resemble our initial table example.

    Last Name  First Name  Address             City       State  Zip Code
    ---------------------------------------------------------------------
    Adams      Gwendolyn    205 W Third St.    Brownville AL     35020
    Johnson    Diane        82 Richardson Ave. Fresno     CA     93702
    Smith      Harold      321 Elm St.         Portsmouth RI     02871

    Of course returning every record might not be desired. The keyword WHERE may be used to set forth conditions to satisfy when selecting matching records.

    SELECT * FROM addresses WHERE state = "CA";

    Such a query would return only the records where the abbreviation for California appears in the state field.

    Last Name  First Name  Address             City    State  Zip Code
    ------------------------------------------------------------------
    Johnson    Diane        82 Richardson Ave. Fresno  CA     93702

    AND and OR may also be used to identify more than one field when constructing a WHERE condition.

    SELECT * FROM employees WHERE first_name = "Diane" AND
    last_name = "Johnson";

    Such a query would return only the records where the value of first_name is Diane and the value of last_name is Johnson.

    ID   First Name  Last Name  Date Hired  Notes
    -----------------------------------------------------------------------
    189  Diane       Johnson    2001-07-15  secretary of the year for 2003

    As mentioned earlier, the asterisk is a shorthand request for all fields. Individual fields may be requested by listing them after SELECT. Commas separate multiple requested fields.

    SELECT first_name, last_name FROM addresses;

    Such a query would return just the values of the first_name and last_name fields in the address table.

    First Name  Last Name
    ---------------------
    Gwendolyn   Adams
    Diane       Johnson
    Harold      Smith

    More Database Articles Articles
    More By bluephoenix

    blog comments powered by Disqus

    DATABASE ARTICLES ARTICLES

    - Completing a Book Inventory Management System
    - Uploading Images for a Book Inventory Manage...
    - Finishing the Add Book Story for a Book Inve...
    - Integration Testing for a Book Inventory Man...
    - User Stories for a Book Inventory Management...
    - Unit Testing a Book Inventory Management Sys...
    - Testing a Book Inventory Management System
    - Implementing Models for a Book Inventory Man...
    - Book Inventory Application: Publishers and B...
    - Handling Publishers in a Book Inventory Mana...
    - Publisher Administration for Book Inventory ...
    - Book Inventory Management
    - Using the SQL Reference Manual
    - Using Oracle SQL Developer with SQL Statemen...
    - Fixing Errors with Oracle SQL Developer


    © 2003-2012 by Developer Shed. All rights reserved. DS Cluster 6 - Follow our Sitemap