2015-04-03 108 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