SQL:数据按多列去重

文章目录

  • 1.用 group by 按多列分组
  • 2.用 distinct 按多列去重

1.用 group by 按多列分组

  • 可以用 group_concat() 函数把不需要去重列的数据也取出来。
select group_concat(interfaceid), ip, port from interface group by ip, port;

2.用 distinct 按多列去重

  • distinct 可以对多列去重。不能把不需要去重列的数据取出来,且 distinct 必须放在最前面。
select distinct ip, port from interface;

你可能感兴趣的:(MySQL,sql,服务器,网络)