MySQL根据一行的唯一性选择DISTINCT多列? [英] MySQL Select DISTINCT multiple columns based on the uniqueness of one row?

查看:76
本文介绍了MySQL根据一行的唯一性选择DISTINCT多列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图了解此查询的确切作用:

I'm trying to understand what this query does exactly:

SELECT DISTINCT `state`, `state_name` FROM `geo` ORDER BY `state_name` ASC

我想要做的就是选择2列(状态和状态名称),我只想要唯一的行,而该行没有状态字段的重复值.我不在乎state_name字段中是否存在重复的值.

All I'm trying to do is select 2 columns (state and state_name), I want only unique rows that do not have duplicate values for the state field. I don't care if there are duplicate values in the state_name field.

我的查询正在检查两列的唯一性还是只是状态?

Is my query checking both columns for uniqueness or just state?

推荐答案

DISTINCT将仅返回不同的行,因此:

DISTINCT will return only distinct rows, so:

我的查询正在检查两列的唯一性还是只是状态?

Is my query checking both columns for uniqueness or just state?

两列

您也可以改为使用GROUP BY.

You could also switch to GROUP BY instead.

SELECT `state`, `state_name` FROM `geo` group by 'state', 'state_name' ORDER BY `state_name` ASC 

这篇关于MySQL根据一行的唯一性选择DISTINCT多列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆