[randy@euclid randy]$ mysql -p -u nations nations Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 8151 to server version: 3.23.36 Type 'help;' or '\h' for help. Type '\c' to clear the buffer # # Create a table of airplanes and their speeds # mysql> create table speed (Name char(20) not null, speed int); Query OK, 0 rows affected (0.00 sec) # # Create a table of airplanes and their prices # mysql> create table price (Name char(20) not null, price decimal(8,2)); Query OK, 0 rows affected (0.00 sec) # # Check to see that the table price is right # mysql> describe price; +-------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+--------------+------+-----+---------+-------+ | Name | char(20) | | | | | | price | decimal(8,2) | YES | | NULL | | +-------+--------------+------+-----+---------+-------+ 2 rows in set (0.00 sec) # # Insert into the database some data # mysql> insert into speed values ("C-150", 110); Query OK, 1 row affected (0.00 sec) mysql> insert into speed values ("C-172", 130); Query OK, 1 row affected (0.00 sec) mysql> insert into price values ("C-150", 14500); Query OK, 1 row affected (0.00 sec) mysql> insert into price values ("C-172", 29999.99); Query OK, 1 row affected (0.00 sec) # # Get the airplanes that exist in the prices table # mysql> select name from price; +-------+ | name | +-------+ | C-150 | | C-172 | +-------+ 2 rows in set (0.00 sec) # # Find the price and speed of all the airplanes # This is the WRONG WAY to do it # mysql> select price.Name, price.Price, speed.Speed from price, speed; +-------+----------+-------+ | Name | Price | Speed | +-------+----------+-------+ | C-150 | 14500.00 | 110 | | C-172 | 29999.99 | 110 | | C-150 | 14500.00 | 130 | | C-172 | 29999.99 | 130 | +-------+----------+-------+ 4 rows in set (0.00 sec) # # Find all planes and their speed and price # This is the RIGHT WAY to do this # mysql> select price.Name, price.Price, speed.Speed from price, speed where price.name=speed.name; +-------+----------+-------+ | Name | Price | Speed | +-------+----------+-------+ | C-150 | 14500.00 | 110 | | C-172 | 29999.99 | 130 | +-------+----------+-------+ 2 rows in set (0.00 sec) # # Get the name, price, and speed of all cheap airplanes # mysql> select price.Name, price.Price, speed.Speed from price, speed where price.name=speed.name and price < 20000; +-------+----------+-------+ | Name | Price | Speed | +-------+----------+-------+ | C-150 | 14500.00 | 110 | +-------+----------+-------+ 1 row in set (0.00 sec) # # Get the planes from fastest to slowest # mysql> select * from speed order by speed desc; +-------+-------+ | Name | speed | +-------+-------+ | C-172 | 130 | | C-150 | 110 | +-------+-------+ 2 rows in set (0.00 sec) # # Add up the prices of all the planes # mysql> select sum(price) from price; +------------+ | sum(price) | +------------+ | 34499.99 | +------------+ 1 row in set (0.00 sec) # # Delete the C-172 from the airplane database; # mysql> delete from price where name = "C-172"; Query OK, 1 row affected (0.00 sec) mysql> delete from speed where name = "C-172"; Query OK, 1 row affected (0.00 sec) # # Delete all cheap planes from the database #