Linux 拨号vps windows公众号手机端

sql中distinct函数的作用是什么

lewis 7年前 (2018-11-30) 阅读数 11 #VPS/云服务器
文章标签 sql

在SQL中,DISTINCT函数的作用是返回不重复的行/记录。它应用于SELECT语句中的列,用来排除重复的值,只返回唯一的值。

例如,假设有一个名为"customers"的表,包含以下数据:

customer_id customer_name city
1 John London
2 Mary Paris
3 John Berlin
4 David London

如果我们执行以下SQL查询:

SELECT DISTINCT customer_name, city FROM customers;

结果将会是:

customer_name city
John London
Mary Paris
David London
John Berlin

可以看到,DISTINCT函数只返回唯一的customer_name和city组合,去除了重复的行。

版权声明

本文仅代表作者观点,不代表米安网络立场。

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

热门