[英]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.