从多个表中检索数据 从 Ms 访问

本文关键字:数据 Ms 访问 检索 | 更新日期: 2023-09-27 18:32:16

我做了两个表,一个是exp_detail,第二个是exp_head

  • exp_detail 表包含 exp_id、Amount_paid、sr_no 和exp_Description

  • exp_head表包含exp_id和exp_Name

现在,我使用此查询从表中检索数据exp_detail。这将正确显示。此查询是

select sr_no, e_date, e_paid, e_des 
from exp_detail 
where e_date = #" + this.dp_expDetail.Value.Date + 
"# order by exp_detail.sr_no"

但问题是我在上面给定的查询中使用主键和外键从表中检索exp_head exp_Name。怎么可能?

从多个表中检索数据 从 Ms 访问

必须使用 SQL 联接来联接这两个表。使用连接语句引用下面更新的 sql 语句,即第 3 行

select sr_no, e_date, e_paid, e_des 
  from exp_detail 
 inner join exp_head on exp_detail.exp_id = exp_head.exp_id --This is added--
 where e_date=#" + this.dp_expDetail.Value.Date + "# 
 order by exp_detail.sr_no