简体   繁体   English

选择查询Ms访问中的子查询

[英]Sub Query in Select query Ms access

Can I add in sub query in ms access something like : 我可以在ms access中添加子查询吗?

select field1,field2,field3, 
(select field4 from table2 where field5 = field3)  from table1

I tried the same and the sub query brings values for every line.I need it to display the value only when field5 = field3 我尝试了相同的方法,并且子查询为每一行都带来了值。我需要它仅在field5 = field3时才显示值

as per discusion you can try this 根据讨论,您可以尝试一下

Select field1, field2,field3 + (select
IIF(IsNull(sum(field4)),0,sum(field4)) from table2 where table2field5 = 
table2.fields3) from table1

Try left join between two table 尝试在两个表之间左连接

select table1.field1,table1.field2,table1.field3,table2.field4
from table1 left outer join table2 on
 table1.field5= table2.field3

you can try like this, I think you are trying subquery and you are trying copare table1 column to table2 column 您可以尝试这样,我想您正在尝试子查询,并且您正在尝试将copare table1列转换为table2列

select field1,field2,field3, 
 (select field4 from table2 where table2. field5 = field3) from table1

or 要么

select field1,field2,field3,
  (select field4 from table2 where field5 = table2.field3) from table1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM