mysql 关于子查询的一个问题

2025-03-23 08:37:28
推荐回答(3个)
回答1:

select T2.C
from T2
where Exists(select *
from T1,T3
where T1.B=T2.B and T2.C=T3.C and D='value');
你想输出C的话,主查询里from T2或T3都可以。

回答2:

select t1.A,t.B,t.C
from t1,(select T2.B,T3.C from t2 join t3 on t2.C=t3.C) t
where t1.B=t.B;

回答3:

Semi-join 限制

不过并不是所有子查询都是半联接,必须满足以下条件:

  • 子查询必须是出现在顶层的 WHERE、ON 子句后面的 IN 或者 =ANY
  • 子查询必须是单个 select,不能是 union;
  • 子查询不能有 group by 或者 having 子句(可以用 semijoin materialization 策略,其他不可以 );
  • It must not be implicitly grouped (it must contain no aggregate functions). (不知道啥意思,保持原文);
  • 子查询不能有 order by with limit;
  • 父查询中不能有 STRAIGHT_JOIN 指定联接顺序;
  • The number of outer and inner tables together must be less than the maximum number of tables permitted in a join.