我正在尝试两个嵌套查询。
select * from
select a.*, b.* from(
(select AAA, BBB from Atable) a) as AA,
select * from (
(select QQQ, BBB from Btable)b) as BB
where AA.AAA = 'Y' and AA.BBB = BB.BBB
有可能做这样的事情吗?
我正在尝试两个嵌套查询。
select * from
select a.*, b.* from(
(select AAA, BBB from Atable) a) as AA,
select * from (
(select QQQ, BBB from Btable)b) as BB
where AA.AAA = 'Y' and AA.BBB = BB.BBB
有可能做这样的事情吗?
你可以做:
select * from
(select AAA, BBB from Atable) a
inner join
(select QQQ, BBB from Btable)b
on
a.BBB = b.BBB
where a.AAA = 'Y'
我不确定您的问题中额外的嵌套和别名级别试图实现什么。
你为什么要改为查询这种类型的查询
select *
from
select a.*, b.*
from
(
(select AAA, BBB from Atable) a) as AA,
select *
from (
(select QQQ, BBB from Btable) b) as BB
where
AA.AAA = 'Y' and AA.BBB = BB.BBB
您可以像这样使用任何连接,如内连接、左外连接等
select
AA.AAA, AA.BBB, BB.QQQ
from
Atable as AA
inner join
Btable as BB ON BB.BBB = AA.BBB
where
AA.AAA = 'Y'