19.12.2012 Views

Computer Programming Concepts and Visual Basic David I. Schneider

Computer Programming Concepts and Visual Basic David I. Schneider

Computer Programming Concepts and Visual Basic David I. Schneider

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

334 <strong>Computer</strong> <strong>Programming</strong> <strong>Concepts</strong> <strong>and</strong> <strong>Visual</strong> <strong>Basic</strong><br />

III (b) Show the records from the joined table whose currency has “u” as its second letter.<br />

SELECT * FROM Cities INNER JOIN Countries ON Cities.country =<br />

Countries.country WHERE currency Like ‘?u*’<br />

IV (a) Make available just the city <strong>and</strong> country fields of the table Cities.<br />

SELECT city, country FROM Cities<br />

IV (b) Make available just the city <strong>and</strong> currency fields of the joined table.<br />

SELECT city,, currency FROM Cities INNER JOIN Countries ON Cities.country<br />

= Countries.country<br />

Note: In several of the statements, the single quote, rather than the normal double quote was<br />

used to surround strings. This is st<strong>and</strong>ard practice with SQL statements.<br />

We can think of an SQL statement as creating in essence a new “virtual” table from<br />

existing tables. For instance, we might regard the statement<br />

SELECT city, pop2015 FROM Cities WHERE pop2015 >= 20<br />

as creating the “virtual” table<br />

city pop2015<br />

Tokyo 28.7<br />

Sao Paulo 20.8<br />

Bombay 27.4<br />

Shanghai 23.4<br />

This table is a subtable of the original table Cities, that is, it consists of what is left after certain<br />

columns <strong>and</strong> rows are deleted.<br />

As another example, the statement<br />

SELECT Cities.city, Cities.Country, Country.currency FROM Cities INNER JOIN<br />

Countries ON Cities.country = Countries.country WHERE Countries.country>’K’<br />

creates in essence the “virtual” table<br />

Cities.city Cities.country currency<br />

New York USA dollar<br />

Mexico City Mexico peso<br />

Los Angeles USA dollar<br />

which is a subtable of a join of the two tables Cities <strong>and</strong> Countries.<br />

These “virtual” tables don’t really exist physically. However, for all practical purposes,<br />

<strong>Visual</strong> <strong>Basic</strong> acts as if they did. In <strong>Visual</strong> <strong>Basic</strong> terminology, a “virtual” table is called a<br />

recordset <strong>and</strong> SQL statements are said to create a recordset. In st<strong>and</strong>ard relational database<br />

books, a “virtual” table is called a view.<br />

SQL also can be used in code with a statement of the form<br />

Data1.RecordSource = “ SELECT ... FROM ...”<br />

to alter the order <strong>and</strong> kinds of records presented from a database. However, such a statement<br />

must be followed by the statement<br />

Data1.Refresh<br />

to reset the information processed by the data control.<br />

EXAMPLE 1<br />

The following program allows the user to alter the order <strong>and</strong> kinds of information displayed from a database.<br />

When the first comm<strong>and</strong> button is pressed, the cities are presented in ascending order based on their

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!