2012-03-18 9 views
0

I以下の4つの選択があります。 MySQLの+ヘルプ作成UNIONクエリ

select english,type from table where type='brief' ORDER BY RAND() LIMIT 5; 
select english,type from table where type='small' ORDER BY RAND() LIMIT 5; 
select english,type from table where type='medium' ORDER BY RAND() LIMIT 5; 
select english,type from table where type='large'; 

はむしろ、私はむしろ1 UNIONとしてこれを実行します複数のクエリを作る - すべて同じ形式になってからも出力を見て。

私は以下を試しましたが、RAND()は動作していません。そこ種類ごとに約10のオプションがありますが、私は同じ5いうし、ランダムなリターンを見続ける:

select english,type from table where type='brief' LIMIT 5 
UNION 
select english,type from table where type='small' LIMIT 5 
UNION 
select english,type from table where type='medium' LIMIT 5 
UNION 
select english,type from table where type='large' ORDER BY type,RAND(); 

真のランダムリターンでこのUNIONを実行する方法上の任意のアドバイスを? THX

答えて

1

あなたは別で組合を囲む必要があり、全組合で注文したい場合は

は次のように選択します。

SELECT (
select english,type from table where type='brief' LIMIT 5 
UNION 
select english,type from table where type='small' LIMIT 5 
UNION 
select english,type from table where type='medium' LIMIT 5 
UNION 
select english,type from table where type='large' 
) 
ORDER BY type, RAND();