MySQL选择一列DISTINCT,与对应的其他列 [英] MySQL select one column DISTINCT, with corresponding other columns

查看:43
本文介绍了MySQL选择一列DISTINCT,与对应的其他列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ID   FirstName   LastName
1      John        Doe
2      Bugs        Bunny
3      John        Johnson

我想从 FirstName 列中选择 DISTINCT 结果,但我需要相应的 IDLastName.

I want to select DISTINCT results from the FirstName column, but I need the corresponding ID and LastName.

结果集只需要显示一个 John,但 ID 为 1,LastName 为 Doe.

The result set needs to show only one John, but with an ID of 1 and a LastName of Doe.

推荐答案

试试这个查询

 SELECT ID, FirstName, LastName FROM table GROUP BY(FirstName)

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

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