[英]SQL Query to select multiple rows with ID
我需要从表中选择所有行(参见下面的结构),但这更复杂。
我想要 5 个唯一的idm,但所有行都带有这个idm (这是对话的 ID)。我该怎么做?
+------------+
| messagerie |
+------------+
| ID |
| idm |
| send |
| receipt |
| subject |
| message |
+------------+
distinct
idms 以获得唯一性,并使用LIMIT
关键字仅选择5
。idm
所有行。idms
随机为您提供 5 个唯一idms
。查询语句:
select *
from messagerie m1
inner join (select distinct idm
from messagerie
order by rand() LIMIT 5) m2
on m1.idm = m2.idm;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.