当前位置:网站首页>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 .
边栏推荐
- 基于Caffe ResNet-50网络实现图片分类(仅推理)的实验复现
- 如何解决跨域问题
- 2016 CCPC network trial c-change root DP good question
- Introduction to redis
- C # fine sorting knowledge points 12 exception handling (recommended Collection)
- Wavelet transform --dwt2 and wavedec2
- 用GaussDB(for Redis)存画像,推荐业务轻松降本60%
- 对this对象的理解
- 报表工具的二次革命
- 面试8家公司,1周拿了5个offer,分享一下自己的心得
猜你喜欢

LeetCode - 225 用队列实现栈

How matlab produces random complex sequences

CVPR 2022 | 网络中批处理归一化估计偏移的深入研究

基于Caffe ResNet-50网络实现图片分类(仅推理)的实验复现

Leetcode - 303 area and retrieval - array immutable (design prefix and array)

LeetCode - 641 设计循环双端队列(设计)*

电阻电路的等效变化(Ⅱ)

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

Matlab -- CVX optimization kit installation

Leetcode - 380 o (1) time to insert, delete and get random elements (design hash table + array)
随机推荐
Matlab randInt, matlab randInt function usage "recommended collection"
Where is there a demo to set up the flex CDC to draw the number of MySQL?
ML - Speech - Introduction to speech processing
MATLAB optimization tool manopt installation
Data system partition design - partition and secondary index
2021hncpc-e-difference, thinking
How to realize page inclusion
【莎士比亚:保持做人的乐趣】
哪里有搭建flink cdc抽mysql数的demo?
30 lines write the concurrency tool class yourself (semaphore, cyclicbarrier, countdownlatch)
Introduction to redis
活动回顾|7月6日安远AI x 机器之心系列讲座第2期|麻省理工教授Max Tegmark分享「人类与AI的共生演化 」
LeetCode - 225 用队列实现栈
# JWT 图解
CircleIndicator组件,使指示器风格更加多样化
TypeError: Unrecognized value type: <class ‘str‘> ParserError: Unknown string format
Basic usage of MFC thread afxbeginthread, passing multiple parameters
Pat grade a 1153 decode registration card of PAT (25 points)
MySQL教程68-AS 设置别名
LeetCode - 677 键值映射(设计)*