meta name="google-site-verification" content="5WnqBAqGhoY5qGR6vWeOU46UM0maXZMbAaLr-28Vvhw" /> learning db2: Retrieving Data from the Database

Retrieving Data from the Database

Retrieving Data from the Database

Data is retrieved from the tables through SQL queries. SQL is a very powerful language, and entire books have been written about it. We will not attempt to teach you SQL but rather will introduce its basic concepts. An SQL query can be broken into three major sections:

  • The type of information you want to retrieve
  • Where you want the information retrieved from
  • What information you want and how it is retrieved
The following simple query will retrieve the description and retail price for all items in the PRODUCT table whose retail price is less than $5:
SELECT description, retail_price

FROM l8nite.product

WHERE retail_price < 5.00

The following more complex query will retrieve the products sold in the most recent transaction:
SELECT a.description, b.product_id, b.price, b.qty, b.total

  FROM l8nite.product a, l8nite.product_purchases b

 WHERE a.product_id=b.product_id AND

                b.sales_transaction_id=identity_val_local()

0 comments:

Post a Comment