select a, b, c
from table_A
order by random()
union all
select a, b, c
from table_B
order by random()
UNION으로 합쳐진 정보를 랜덤으로 정렬하기 위해 ORDER BY RANDOM() 사용시 다음과 같은 에러 발생.
1st ORDER BY term does not match any column in the result set
데이터를 검색하는 쿼리를 from절의 서브쿼리로 만듦
select * from (
select a, b, c
from table_A
order by random()
)
union all
select * from (
select a, b, c
from table_B
order by random()
)
물론 두 합쳐지는 두 쿼리의 select 대상은 같아야함.