mysql 的where查詢子句

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)


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章