当前位置:网站首页>MySQL tutorial 67- filter duplicate data using distinct
MySQL tutorial 67- filter duplicate data using distinct
2022-07-25 15:59:00 【51CTO】
stay MySQL Use in SELECT Statement when executing a simple data query , All matching records are returned . If some fields in the table have no uniqueness constraints , Then there may be duplicate values in these fields . In order to query non duplicate data ,MySQL Provides DISTINCT keyword .
DISTINCT The main function of keyword is to filter the duplicate data of one or more fields in the data table , Only one piece of data is returned to the user .
DISTINCT The syntax format of the keyword is :
among ,“ Field name ” Name the field to be de duplicated , Multiple fields are separated by commas .
Use DISTINCT You should pay attention to the following points when using keywords :
- DISTINCT Keywords can only be found in SELECT Use in statement .
- When de duplicating one or more fields ,DISTINCT Keywords must be at the top of all fields .
- If DISTINCT There are multiple fields after the keyword , Multiple fields will be combined to remove duplicate , in other words , Only when multiple fields are combined to be exactly the same will they be de duplicated .
example 1
The following is a specific example to illustrate how to query non duplicate data .
test In the database student The table structure and data of the table are as follows :
Results show ,student Presence in table 6 Bar record .
Following pair student Tabular age The fields are de duplicated ,SQL Statement and run results are as follows :
Yes student Tabular name and age The fields are de duplicated ,SQL Statement and run results are as follows :
Yes student All fields in the table are de duplicated ,SQL Statement and run results are as follows :
because DISTINCT It can only return its target field , No other fields can be returned , So in reality , We use it a lot DISTINCT Keyword to return the number of non repeating fields .
Inquire about student The table is right name and age Number of records after field de duplication ,SQL Statement and run results are as follows :
Results show ,student The table is right name and age After the field is de duplicated 5 Bar record .
边栏推荐
- 哪里有搭建flink cdc抽mysql数的demo?
- Redis distributed lock, it's really impossible without it
- Pytorch学习笔记--常用函数总结2
- LeetCode - 622 设计循环队列 (设计)
- Wavelet transform --dwt2 and wavedec2
- 2022-07-25日报:微软提出CodeT:代码生成新SOTA,20个点的性能提升
- 【IJCAI 2022】参数高效的大模型稀疏训练方法,大幅减少稀疏训练所需资源
- Leetcode - 622 design cycle queue (Design)
- Reasons for data format conversion when matlab reads the displayed image
- Leetcode - 232 realize queue with stack (design double stack to realize queue)
猜你喜欢

Pytoch learning notes -- seresnet50 construction

Idea - click the file code to automatically synchronize with the directory

【莎士比亚:保持做人的乐趣】

Cf888g clever dictionary tree + violent divide and conquer (XOR minimum spanning tree)

SVD singular value decomposition derivation and application and signal recovery

Pytoch learning notes -- Summary of common functions of pytoch 1

MySQL—常用SQL语句整理总结

LeetCode - 380 O(1) 时间插入、删除和获取随机元素 (设计 哈希表+数组)

Pytoch learning notes advanced_ CNN (using perception_module) implements MNIST dataset classification - (comments and results)

华为2023届提前批预热开始!左 神的程序代码面试指南终派上用场
随机推荐
Activity review | July 6 Anyuan AI X machine heart series lecture No. 2 | MIT professor Max tegmark shares "symbiotic evolution of human and AI"
JVM—类加载器和双亲委派模型
华为2023届提前批预热开始!左 神的程序代码面试指南终派上用场
Leetcode - 707 design linked list (Design)
电阻电路的等效变化(Ⅱ)
IDEA—点击文件代码与目录自动同步对应
通用测试用例写作规范
Leetcode - 622 design cycle queue (Design)
推荐收藏,这或许是最全的类别型特征的编码方法总结
How Google cloud disk is associated with Google colab
Gary marcus: learning a language is more difficult than you think
2019 Shaanxi Provincial race K-variant Dijstra
MySQL—用户和权限管控
TypeError: Unrecognized value type: <class ‘str‘> ParserError: Unknown string format
MySQL—常用SQL语句整理总结
MySQL教程68-AS 设置别名
Zhaoqi Kechuang high-level innovation and Entrepreneurship Talent Service Platform at home and abroad, mass entrepreneurship and innovation achievement transformation platform
2021 Jiangsu race a Array line segment tree, maintain value range, Euler power reduction
Cf888g clever dictionary tree + violent divide and conquer (XOR minimum spanning tree)
LeetCode - 359 日志速率限制器 (设计)