Oracle 5.0 Reference Manual page 222

Table of Contents

Advertisement

+----------+--------+---------+------+------------+------------+
| Fluffy
| Claws
| Buffy
| Fang
| Bowser
| Chirpy
| Whistler | Gwen
| Slim
| Puffball | Diane
+----------+--------+---------+------+------------+------------+
This form of
loaded it with your initial data set. For example, you may happen to think that the birth date for Bowser
doesn't seem quite right. Consulting your original pedigree papers, you find that the correct birth year
should be 1989, not 1979.
There are at least two ways to fix this:
• Edit the file
DATA:
mysql>
DELETE FROM pet;
mysql>
LOAD DATA LOCAL INFILE 'pet.txt' INTO TABLE pet;
However, if you do this, you must also re-enter the record for Puffball.
• Fix only the erroneous record with an
mysql>
UPDATE pet SET birth = '1989-08-31' WHERE name = 'Bowser';
The
UPDATE
3.3.4.2. Selecting Particular Rows
As shown in the preceding section, it is easy to retrieve an entire table. Just omit the
from the
SELECT
becomes large. Instead, you're usually more interested in answering a particular question, in which
case you specify some constraints on the information you want. Let's look at some selection queries in
terms of questions about your pets that they answer.
You can select only particular rows from your table. For example, if you want to verify the change that
you made to Bowser's birth date, select Bowser's record like this:
mysql>
SELECT * FROM pet WHERE name = 'Bowser';
+--------+-------+---------+------+------------+------------+
| name
| owner | species | sex
+--------+-------+---------+------+------------+------------+
| Bowser | Diane | dog
+--------+-------+---------+------+------------+------------+
The output confirms that the year is correctly recorded as 1989, not 1979.
String comparisons normally are case-insensitive, so you can specify the name as 'bowser',
'BOWSER', and so forth. The query result is the same.
You can specify conditions on any column, not just name. For example, if you want to know which
animals were born during or after 1998, test the
mysql>
SELECT * FROM pet WHERE birth >= '1998-1-1';
+----------+-------+---------+------+------------+-------+
| name
+----------+-------+---------+------+------------+-------+
| Chirpy
| Puffball | Diane | hamster | f
Retrieving Information from a Table
| Harold | cat
| f
| Gwen
| cat
| m
| Harold | dog
| f
| Benny
| dog
| m
| Diane
| dog
| m
| Gwen
| bird
| f
| bird
| NULL | 1997-12-09 | NULL
| Benny
| snake
| m
| hamster | f
is useful if you want to review your entire table, for example, after you've just
SELECT
to correct the error, then empty the table and reload it using
pet.txt
changes only the record in question and does not require you to reload the table.
statement. But typically you don't want to see the entire table, particularly when it
| m
| owner | species | sex
| Gwen
| bird
| f
| 1993-02-04 | NULL
| 1994-03-17 | NULL
| 1989-05-13 | NULL
| 1990-08-27 | NULL
| 1979-08-31 | 1995-07-29 |
| 1998-09-11 | NULL
| 1996-04-29 | NULL
| 1999-03-30 | NULL
statement:
UPDATE
| birth
| death
| 1989-08-31 | 1995-07-29 |
column:
birth
| birth
| death |
| 1998-09-11 | NULL
| 1999-03-30 | NULL
202
|
|
|
|
|
|
|
|
|
|
|
and
DELETE
LOAD
clause
WHERE

Advertisement

Table of Contents
loading

This manual is also suitable for:

Mysql 5.0

Table of Contents