Oracle 5.0 Reference Manual page 228

Table of Contents

Advertisement

When doing an
you do
ORDER BY ...
A common error when working with
empty string into a column defined as
whereas
NULL
as shown:
mysql>
SELECT 0 IS NULL, 0 IS NOT NULL, '' IS NULL, '' IS NOT NULL;
+-----------+---------------+------------+----------------+
| 0 IS NULL | 0 IS NOT NULL | '' IS NULL | '' IS NOT NULL |
+-----------+---------------+------------+----------------+
|
0 |
+-----------+---------------+------------+----------------+
Thus it is entirely possible to insert a zero or empty string into a
NULL. See
NOT
3.3.4.7. Pattern Matching
MySQL provides standard SQL pattern matching as well as a form of pattern matching based on
extended regular expressions similar to those used by Unix utilities such as vi, grep, and sed.
SQL pattern matching enables you to use "_" to match any single character and "%" to match an
arbitrary number of characters (including zero characters). In MySQL, SQL patterns are case-
insensitive by default. Some examples are shown here. You do not use
patterns; use the
To find names beginning with "b":
mysql>
SELECT * FROM pet WHERE name LIKE 'b%';
+--------+--------+---------+------+------------+------------+
| name
| owner
+--------+--------+---------+------+------------+------------+
| Buffy
| Harold | dog
| Bowser | Diane
+--------+--------+---------+------+------------+------------+
To find names ending with "fy":
mysql>
SELECT * FROM pet WHERE name LIKE '%fy';
+--------+--------+---------+------+------------+-------+
| name
| owner
+--------+--------+---------+------+------------+-------+
| Fluffy | Harold | cat
| Buffy
| Harold | dog
+--------+--------+---------+------+------------+-------+
To find names containing a "w":
mysql>
SELECT * FROM pet WHERE name LIKE '%w%';
+----------+-------+---------+------+------------+------------+
| name
+----------+-------+---------+------+------------+------------+
| Claws
| Bowser
| Whistler | Gwen
+----------+-------+---------+------+------------+------------+
To find names containing exactly five characters, use five instances of the "_" pattern character:
mysql>
SELECT * FROM pet WHERE name LIKE '_____';
+-------+--------+---------+------+------------+-------+
| name
| owner
+-------+--------+---------+------+------------+-------+
| Claws | Gwen
| Buffy | Harold | dog
+-------+--------+---------+------+------------+-------+
Retrieving Information from a Table
values are presented first if you do
ORDER
BY,
NULL
DESC.
means "not having a value." You can test this easily enough by using
1 |
Section C.5.5.3, "Problems with
[896]
or
LIKE
NOT LIKE
| species | sex
| f
| dog
| m
| species | sex
| f
| f
| owner | species | sex
| Gwen
| cat
| m
| Diane | dog
| m
| bird
| NULL | 1997-12-09 | NULL
| species | sex
| cat
| m
| f
is to assume that it is not possible to insert a zero or an
NULL
NULL, but this is not the case. These are in fact values,
NOT
0 |
Values".
NULL
[898]
comparison operators instead.
| birth
| death
| 1989-05-13 | NULL
| 1989-08-31 | 1995-07-29 |
| birth
| death |
| 1993-02-04 | NULL
| 1989-05-13 | NULL
| birth
| death
| 1994-03-17 | NULL
| 1989-08-31 | 1995-07-29 |
| birth
| death |
| 1994-03-17 | NULL
| 1989-05-13 | NULL
208
ORDER BY ... ASC
1 |
column, as these are in fact
NOT NULL
or
when you use SQL
=
<>
|
|
|
|
|
|
|
|
|
and last if
IS [NOT] NULL

Advertisement

Table of Contents
loading

This manual is also suitable for:

Mysql 5.0

Table of Contents