2013-10-16 81 views
2
select (select Nombre 
     from Pacientes 
     where idPacientes= any(select idPaciente 
           from Citas 
           where Dias_idDia= any(select idDia 
                 from Dias 
                 where fecha = '2013-10-15'))) as 'Nombre',horaInicio, horaTermino,actividad,observacion,recordar,ciudad,tipoCita 
from Citas 
where Dias_idDia = any (select idDia 
         from Dias 
         where fecha='2013-10-15') 
order by horaInicio; 

我有錯誤1242,如果有人可以幫助解決這個問題,因爲它給我在我的系統這麼多麻煩。 TY我有錯誤1242子查詢返回超過1行

+0

看到加入。祝你好運。 – Strawberry

回答

4

從子查詢的行數不正確:

ERROR 1242(ER_SUBSELECT_NO_1_ROW) SQLSTATE = 21000 消息= 「子查詢返回多1行」 的發言,其中子查詢必須至多返回發生 此錯誤一行但返回多行。考慮以下示例:

SELECT * FROM t1 WHERE column1 = (SELECT column1 FROM t2); 

如果SELECT column1 FROM t2只返回一行,則以前的查詢將會起作用。如果子查詢返回多個行,則會發生錯誤1242。在這種情況下,查詢應該被改寫爲:

SELECT * FROM t1 WHERE column1 = ANY (SELECT column1 FROM t2); 

Reference

+0

你可以給這個問題一些具體的答案嗎? Leo的查詢是什麼或什麼可能是錯誤的? – RAS

+0

獅子座的查詢是糟糕的。他應該讀一本書。 – Strawberry

+0

@andy但據我所知,Leo在所有3個子查詢中都使用了「= ANY」。他不是在任何子查詢中只使用'='。那麼哪個查詢或子查詢可能是錯誤的? – RAS

1
select (select Nombre 
     from Pacientes 
     where idPacientes in (select idPaciente 
          from Citas 
          where Dias_idDia in (select idDia 
                from Dias 
                where fecha = '2013-10-15'))) as 
    'Nombre',horaInicio, horaTermino,actividad,observacion,recordar,ciudad,tipoCita 
    from Citas 
    where Dias_idDia in (select idDia 
        from Dias 
        where fecha='2013-10-15') 
    order by horaInicio; 
相關問題