前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >mysql 查询用法

mysql 查询用法

作者头像
零月
发布2018-04-25 16:05:27
2K0
发布2018-04-25 16:05:27
举报
文章被收录于专栏:从零开始的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 删除

本文分享自 从零开始的linux 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
云数据库 SQL Server
腾讯云数据库 SQL Server (TencentDB for SQL Server)是业界最常用的商用数据库之一,对基于 Windows 架构的应用程序具有完美的支持。TencentDB for SQL Server 拥有微软正版授权,可持续为用户提供最新的功能,避免未授权使用软件的风险。具有即开即用、稳定可靠、安全运行、弹性扩缩等特点。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档