heropage wrote:'m having the following table:
Table paragraph
ID | text | number
1|text1|1
2|text2|1
3|text3|1
4|text4|2
5|text5|2
6|text6|3
7|text7|3
8|text8|3
9|text9|3
I need to select 3 random rows that have DISTINCT number.
If you're only ever gonna have 1,2,3 as values you could use this:
select ID from paragraph where number=1 order by rand() limit 1
UNION
select ID from paragraph where number=2 order by rand() limit 1
UNION
select ID from paragraph where number=3 order by rand() limit 1
You could change it as needed by adding more select queries.
This is NOT an optimal solution, but it will work.