Cartesian product with random select mysql

2

I have managed to make the query:

select * from (select x from a ORDER BY rand() limit 15) as a, (select x2 from b) as b

The output is:

1 | a
1 | b
1 | c
3 | a
3 | b
3 | c
2 | a
2 | b
2 | c

But what I need is that really the records in the table to are random for each record of b , there may be some repeated but not all.

Let's see if anyone has any ideas.

    
asked by Marc 09.09.2018 в 00:36
source

1 answer

0

It was not very clear to me what you want to achieve, but maybe this is what you are looking for:

SELECT a.x AS a, b.x2 AS b FROM a INNER JOIN b ORDER BY RAND() LIMIT 15;
    
answered by 09.09.2018 в 17:35