Mysql查询修改

Mysql query modification

我有一个有效的查询 return 结果中有 1 行,但是我得到的结果多于 1 行:错误代码:1242。子查询 return 超过1 行。

即使不止一行,我怎样才能得到return所有的结果?

代码是:

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;

如果将查询的开头更改为:

select numbers 
from vista
where id in (

结束于:

order by id;

查询将 return 所有匹配组后面的数字。

See this example.