SQL:select * from table_a where a_row_1 in (select a_row_1 from table_b where b_id = '123456');单独执行括号中的select a_row_1 from table_b where b_id = '123456' 则会报错说table_b表中没有a_row_1字段
但整体执行这个SQL就可以得出结果,结果集和执行语句select * from table_a一样求助:这是什么原因?SQL是怎么解释的?
但整体执行这个SQL就可以得出结果,结果集和执行语句select * from table_a一样求助:这是什么原因?SQL是怎么解释的?
select * from T_MARK_B
COURSE MARK MARK_SB
--------- ------- ----------
MIDDLE 70 80
END 80 90
END 80 90
MIDDLE 90 100
select * from T_MARK
NAME COURSE MARK MARK_SB
------- --------- ------- ----------
Chinese MIDDLE 70 80
Chinese END 80 90
Math END 80 90
Math MIDDLE 90 100
select * from T_MARK where exists ( select name from T_MARK_B )
原因是 select name from T_MARK_B 中的 name 当作 MARK 中的name 了
a_row_1 是 table_a 表的字段 ,条件加的效果是 where a_row_1=a_row_1 ,因此,结果和 select * from table_a 是一样的。
而是没有起到过滤作用
(select a_row_1 from table_b where b_id = '123456')
首先 a_row_1 是从 table_a 表中查到的值
比如 a_row_1 = 'Chinese'
那么在执行(select a_row_1 from table_b where b_id = '123456') 的时候
就变成了 (select 'Chinese' from table_b where b_id = '123456')
所以没有 起到过滤作用
select * from table_a where a_row_1 in (select table_b.a_row_1 from table_b where b_id = '123456');
如果table_b中没有字段列a_row_1那一定会报错的。