2015-04-03 141 views
0

我有這個查詢,它工作格柵它返回結果1行,但結果發現超過1行我得到:錯誤代碼:1242.子查詢返回多於1行。Mysql查詢修改

即使存在多行,我該如何返回所有結果?

代碼:

select numbers 
from vista 
where id = (
    select b.id + 3 from (
     select t1.id, t1.numbers t1val, t2.numbers t2val, t3.numbers t3val 
     from vista t1 
     join vista t2 on t1.id = t2.id-1 
     join vista t3 on t1.id = t3.id-2 
     where t1.id = (select max(id) - 2 from vista) 
    ) a 
    join (
     select t1.id, t1.numbers t1val, t2.numbers t2val, t3.numbers t3val 
     from vista t1 
     join vista t2 on t1.id = t2.id-1 
     join vista t3 on t1.id = t3.id-2 
     where t1.id < (select max(id) - 2 from vista) 
    ) b 
    on a.t1val = b.t1val 
    and a.t2val = b.t2val 
    and a.t3val = b.t3val 
    and a.id <> b.id 
) 
order by id limit 1; 

回答

0

如果更改查詢的這個開頭:

select numbers 
from vista 
where id in (

和結束:

order by id; 

的查詢將返回跟隨所有匹配組的數字。

See this example.

+0

非常感謝。 – user1385619 2015-04-03 16:46:46