mysql> select * from mytable; +----------+------+------------+-----------+ | name | sex | birth | birthaddr | +----------+------+------------+-----------+ | abccs |f | 1977-07-07 | china | | mary |f | 1978-12-12 | usa | | tom |m | 1970-09-02 | usa | +----------+------+------------+-----------+ |
mysql> create table title(writer varchar(20) not null, -> title varchar(40) not null, -> senddate date); 向该表中填加记录,最后表的内容如下: <ccid_nobr> <table width="400" border="1" cellspacing="0" cellpadding="2" bordercolorlight = "black" bordercolordark = "#FFFFFF" align="center"> <tr> <td bgcolor="e6e6e6" class="code" style="font-size:9pt"> <pre><ccid_code> mysql> select * from title; +--------+-------+------------+ | writer | title | senddate | +--------+-------+------------+ | abccs | a1 | 2000-01-23 | | mary | b1 | 1998-03-21 | | abccs | a2 | 2000-12-04 | | tom | c1 | 1992-05-16 | | tom | c2 | 1999-12-12 | +--------+-------+------------+ 5 rows in set (0.00sec) |
mysql> SELECT name,sex,title FROM mytable,title -> WHERE name=writer AND name=′abccs′; +-------+------+-------+ | name | sex | title | +-------+------+-------+ | abccs | f | a1 | | abccs | f | a2 | +-------+------+-------+ |
mysql> select title,writer,birthaddr,birth from mytable,title -> where mytable.name=title.writer and title=′a2′; +-------+--------+-----------+------------+ | title | writer | birthaddr | birth | +-------+--------+-----------+------------+ | a2 | abccs | china | 1977-07-07 | +-------+--------+-----------+------------+ |
mysql> select * from mytable; +----------+------+------------+-----------+--------+ | name | sex | birth | birthaddr | single | +----------+------+------------+-----------+--------+ | abccs |f | 1977-07-07 | china | y | | mary |f | 1978-12-12 | usa | NULL | | tom |m | 1970-09-02 | usa | NULL | +----------+------+------------+-----------+--------+ |
mysql> insert into mytable -> values (′abc′,′f′,′1966-08-17′,′china′,′n′); Query OK, 1 row affected (0.05 sec) |
mysql> select * from mytable; +----------+------+------------+-----------+--------+ | name | sex | birth | birthaddr | single | +----------+------+------------+-----------+--------+ | abccs |f | 1977-07-07 | china | y | | mary |f | 1978-12-12 | usa | NULL | | tom |m | 1970-09-02 | usa | NULL | | abc |f | 1966-08-17 | china | n | +----------+------+------------+-----------+--------+ |
mysql> select * from mytable; +----------+------+------------+-----------+--------+ | name | sex | birth | birthaddr | single | +----------+------+------------+-----------+--------+ | abccs |f | 1977-07-07 | china | y | | mary |f | 1978-12-12 | usa | NULL | | tom |m | 1970-09-02 | usa | NULL | +----------+------+------------+-----------+--------+ |
use abccs; select * from mytable; select name,sex from mytable where name=′abccs′; |