2011-07-14 26 views
0

我一直在摔跤這個查詢一段時間。那就是:MySQL:JOIN語法+選擇內選擇=操作數錯誤

select First10.mal, Last10.family_name, 
(select * from gender2 
JOIN 
(select * from status) as Mix1 
JOIN 
(select * from age as Mix2 order by rand() limit 10) as Mix3 
JOIN 
(select incidentid from incidentid2 as Mix4) 
as Mix5 where data='mal' and incidentid='6' and status IN ('inj','ali') and age IN ('NULL','0-17') 
order by rand() limit 100) 
from (select fn.mal, @fns := @fns + 1 as Sequence 
from (select mal from fnames where mal IS NOT NULL order by rand() limit 100) fn, 
(select @fns := 0) vars) First10 
JOIN 
(select ln.family_name, @lns := @lns + 1 as Sequence 
from (select family_name from lastnames order by rand() limit 100) ln, 
(select @lns := 0) vars) Last10 
ON First10.Sequence = Last10.Sequence; 

我在這裏的目標是要插入將提出一項隨機姓氏,姓名,性別,身份,年齡,和事件ID的表。我已經嘗試了許多方法來返工這個腳本,包括分離該選擇語句,但我似乎總是與這個錯誤落得:

ERROR 1241 (21000): Operand should contain 1 column(s)

請告知你們,這已經現在強調我出去一會兒..這可能是一個非常簡單的答案,但我只是更加困惑自己。如果您需要任何澄清,請詢問。

回答

0

好吧,它看起來像一個良好的睡眠和朋友的幫助後,我得到了這個查詢工作。對於那些正在尋找類似問題的答案,這裏是我如何得到這個工作:

select mal,family_name,data,age,status,incidentid 
from (select fn.mal, @fns := @fns + 1 as Sequence 
from (select mal from fnames where mal IS NOT NULL order by rand() limit 100) fn, 
(select @fns := 0) vars) as FN 
INNER JOIN 
(select ln.family_name, @lns := @lns + 1 as Sequence 
from (select family_name from lastnames order by rand() limit 100) ln, 
(select @lns := 0) vars) as LN 
INNER JOIN 
(select * from gender2) as Mix0 
INNER JOIN 
(select * from status) as Mix1 
INNER JOIN 
(select * from age as Mix2 order by rand() limit 3) as Mix3 
INNER JOIN 
(select incidentid from incidentid2 as Mix4) 
as Mix5 where data='mal' and incidentid='6' and status IN ('inj','ali') and age IN ('NULL','0-17') 
order by rand() limit 100;