Skip to main content

Database Queries

In the next section we will begin to learn how to design databases like this. For the moment, however, we will concentrate on looking at how queries are handled. Let us take the query "Produce the till receipt for customer transaction CF235692".

First we go to the Purchases table and search down until we find Transaction Code CF235692. From there we can see that this customer has bought item AF123. We then use this information to access the Product table - we search down until we find AF123 and access the Product Name "Stuffalot Dog Treats 1Kg" and the Product Price "1.99". This information can then be added to the customer's bill and printed on the receipt.

We then search for the next occurrence of Transaction Code CF235692 and find that the customer has also ordered Product JL225. Using this information to access the Product table we search down until we find the associated product details: "Chemofed Farm Assured Chicken 2.99".

There are no further items ordered so the customer's bill will be calculated and the till receipt finalised. (We will learn how to do calculations later).

Activity

Show the processing required to answer the query: "Which customer ordered the "Talkia T600 Mobile Phone".

Note that, even though more than one customer is ordering items AF123 and ZE228, the details of these products are only stored once in the database. This is because we have carefully designed the database using a technique called Normalisation which we will learn in the next section.

Next: The Need for Normalisation