Home > Database > Mysql Tutorial > distinct 多列问题结合group by的解决方法

distinct 多列问题结合group by的解决方法

WBOY
Release: 2016-06-07 18:00:19
Original
1139 people have browsed it

distinct 多列问题 group by 解决

表 table1
id RegName PostionSN PersonSN
1 山东齐鲁制药 223 2
2 山东齐鲁制药 224 2
3 北京城建公司 225 2
4 科技公司 225 2

我想获得结果是

id RegName PostionSN PersonSN
1 山东齐鲁制药 223 2
3 北京城建公司 225 2
4 科技公司 225 2

select distinct RegName,PostionSN,PersonSN from table1

如果查询的是多列 distinct 用和不用一样

只能用group by

用group by RegName
select * from table1 where id in (select min(id) from table1 group by RegName) and PersonSN=2
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template