MYSQL + 选择 2 列 - 1 是唯一的 [英] MYSQL + Select 2 columns - 1 being Unique

查看:43
本文介绍了MYSQL + 选择 2 列 - 1 是唯一的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一张如下所示的表格:

I have a table like the following:

 domainname    english
 www.a.com     apples
 www.a.com     peaches
 www.b.com     oranges
 www.b.com     banana
 www.c.com     watermelon

我想随机选择一个域名和英语列表,但域名是唯一的.例如:

I want to select a random list of domainname and english but where the domainname is unique. for example:

 www.a.com     apples
 www.b.com     banana
 www.c.com     watermelon

每次的结果都需要是随机的.

The results need to be random each time.

我已经阅读了该站点上的其他示例并尝试了以下操作,但它没有提供唯一的域名列表 - 例如:它们出现了两次或更多次:

I've read other examples on this site and tried the following but it doesn't give a unique list of domainnames - eg: they show up twice or more:

 SELECT DISTINCT(domainname),english FROM table WHERE domainname ORDER BY RAND();

希望有人能给点建议.

干杯

推荐答案

试试这个查询:

SELECT * FROM (
  SELECT * FROM table ORDER BY RAND()) t
GROUP BY
  domainname

这篇关于MYSQL + 选择 2 列 - 1 是唯一的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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