您好,我是小DAI,专注于数据库管理员相关的技术问答,请问有什么可以帮您?

basic_sql__select__distinct


SQL SELECT DISTINCT 语法
SELECT DISTINCT column1, column2, ...
FROM table_name;

参数说明:

column1, column2, ...:要选择的字段名称,可以为多个字段。如果不指定字段名称,则会选择所有字段。

table_name:要查询的表名称。

在本教程中,我们将使用 RUNOOB 样本数据库。

下面是选自 "Websites" 表的数据:


+----+--------------+---------------------------+-------+---------+
+----+--------------+---------------------------+-------+---------+
<table>
<tr>
<th>1</th>
<th>Google</th>
<th>https://www.google.cm/</th>
<th>1</th>
<th>USA</th>
</tr>
<tr>
<td>3</td>
<td>菜鸟教程</td>
<td>http://www.runoob.com/</td>
<td>4689</td>
<td>CN</td>
</tr>
<tr>
<td>4</td>
<td>微博</td>
<td>http://weibo.com/</td>
<td>20</td>
<td>CN</td>
</tr>
<tr>
<td>5</td>
<td>Facebook</td>
<td>https://www.facebook.com/</td>
<td>3</td>
<td>USA</td>
</tr>
</table>

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

SELECT DISTINCT 实例

下面的 SQL 语句仅从 "Websites" 表的 "country" 列中选取唯一不同的值,也就是去掉 "country" 列重复值:

实例


SELECT DISTINCT country FROM Websites;

来源:https://www.runoob.com/sql/sql-distinct.html