1. 程式人生 > >mysql 的where查詢子句

mysql 的where查詢子句

where子句 地址 row span lec 16px 語句 bsp chang

where條件子句

語法格式:

select * from 表名 where 條件;


例如:

mysql> select * from m1;

+------+------+------+---------+

| id | name | age | address |

+------+------+------+---------+

| 001 | L1 | 4 | 北京 |

| 002 | L2 | 34 | 上海 |

| 003 | L3 | 43 | 廣州 |

| 004 | L4 | 23 | 北京 |

+------+------+------+---------+

4 rows in set (0.00 sec)

只顯示地址為北京的用戶

mysql> select * from m1 where address="北京";

+------+------+------+---------+

| id | name | age | address |

+------+------+------+---------+

| 001 | L1 | 4 | 北京 |

| 004 | L4 | 23 | 北京 |

+------+------+------+---------+

2 rows in set (0.01 sec)


更新表記錄

語法格式:

update 表名 set 字段名=值,字段名=值,... where 條件

註:update語句如果不加where子句,表中所有該記錄都會改變


例如:

將L2的地址修改為北京

mysql> update m1 set address="北京" where name="L2";

Query OK, 1 row affected (0.01 sec)

Rows matched: 1 Changed: 1 Warnings: 0


刪除表記錄

語法:

delete from 表名 where 條件;


例如:

mysql> delete from m1 where id="1";

Query OK, 1 row affected (0.02 sec)


mysql 的where查詢子句