By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
create table t as
SELECT 1 AS id UNION ALL
SELECT 2 UNION ALL
SELECT 3 UNION ALL
SELECT 4 UNION ALL
SELECT 5 UNION ALL
SELECT 6 UNION ALL
SELECT 7 UNION ALL
SELECT 8 UNION ALL
SELECT 9 UNION ALL
SELECT 10;
select t.*,
(select t2.id
from t t2
order by rand()
limit 1
) as id2,
(select t3.id
from t t3
order by rand()
limit 1
) as id3
from t
id | id2 | id3 |
---|---|---|
1 | 8 | 7 |
2 | 4 | 5 |
3 | 8 | 9 |
4 | 9 | 4 |
5 | 1 | 6 |
6 | 3 | 2 |
7 | 7 | 4 |
8 | 7 | 4 |
9 | 10 | 5 |
10 | 5 | 5 |
select t.id, t1.id, t2.id
from (select t.id, (@rn := @rn + 1) as seqnum
from t cross join
(select @rn := 0) params
) t join
(select t.id, (@rn1 := @rn1 + 1) as seqnum
from (select t.* from t order by rand()) t cross join
(select @rn1 := 0) params
) t1
using (seqnum) join
(select t.id, (@rn2 := @rn2 + 1) as seqnum
from (select t.* from t order by rand()) t cross join
(select @rn2 := 0) params
) t2
using (seqnum)
id | id | id |
---|---|---|
1 | 8 | 8 |
2 | 2 | 3 |
3 | 7 | 5 |
4 | 5 | 7 |
5 | 1 | 9 |
6 | 3 | 6 |
7 | 10 | 1 |
8 | 4 | 4 |
9 | 6 | 10 |
10 | 9 | 2 |