I need to select all rows from a table (see structure below) but that's more complex.
I want 5 unique idm but all rows with this idm (which is the ID of a conversation).. How can I do it ?
+------------+
| messagerie |
+------------+
| ID |
| idm |
| send |
| receipt |
| subject |
| message |
+------------+
distinct
idms for uniqueness and use LIMIT
keyword to select only 5
.idm
.idms
at random all the time.SQL:
select *
from messagerie m1
inner join (select distinct idm
from messagerie
order by rand() LIMIT 5) m2
on m1.idm = m2.idm;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.