简体   繁体   English

如何在mysql中查询不同的记录

[英]How to query distinct records in mysql

Hi I want to query unique records using distinct in mysql but the problem is that it only returns a single column, how can I make it return all? 嗨,我想在MySQL中使用distinct查询唯一记录,但问题是它只返回单个列,如何使它返回全部?

Here's my initial query: 这是我的初始查询:

SELECT  distinct(country_name)
FROM HST_LOCATION
WHERE person_id='1897'
ORDER BY date_updated DESC
group by country_name

The GROUP BY clause makes that column distinct, there's no need to use the DISTINCT modifier. GROUP BY子句使该列与众不同,无需使用DISTINCT修饰符。 Just select all the columns and you should get what you want. 只需选择所有列,即可得到所需的内容。

SELECT *
FROM HST_LOCATION
WHERE person_id = '1897'
GROUP BY country_name
ORDER BY date_updated DESC

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM