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)


猜你喜欢

转载自blog.51cto.com/calabash/2139535