首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >mysql 查询用法

mysql 查询用法

作者头像
零月
发布于 2018-04-25 16:05:27
发布于 2018-04-25 16:05:27
2.5K0
举报
文章被收录于专栏:从零开始的linux从零开始的linux

#去重复查询DISTINCT

mysql> select * from student;

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

| uid | name | age |

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

| 3 | hong | 30 |

| 2 | aaa | 20 |

| 1 | bbb | 26 |

| 4 | ccc | 20 |

| 4 | ccc | 30 |

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

5 rows in set (0.00 sec)

mysql> select distinct name from student;

+------+

| name |

+------+

| hong |

| aaa |

| bbb |

| ccc |

+------+

4 rows in set (0.00 sec)

#使用AND和OR进行多条件查询

mysql> select * from student where uid=5 and age<30;

Empty set (0.00 sec)

mysql> select * from student where age>30;

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

| uid | name | age |

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

| 5 | eee | 31 |

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

1 row in set (0.00 sec)

mysql> select * from student where uid<5 or age>30;

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

| uid | name | age |

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

| 2 | aaa | 20 |

| 1 | bbb | 26 |

| 4 | ccc | 20 |

| 3 | ccc | 30 |

| 5 | eee | 31 |

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

5 rows in set (0.00 sec)

#要加括号

mysql> select * from student where name='aaa' and (age=20 or age=30);

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

| uid | name | age |

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

| 2 | aaa | 20 |

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

1 row in set (0.00 sec)

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2017-06-30,如有侵权请联系 cloudcommunity@tencent.com 删除
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档