如何从ms-access中的多个表中检索记录?

时间:2015-03-23 08:23:07

标签: java swing ms-access

我正在尝试将记录复制到JTable中。 我已经成功地从一个数据库表填充了JTable。 现在我想同时从两个表中填充JTable。 我在两个表中都有Call_Status字段,即RMA_Master& Other。 现在我想要有call_Status == 'Open'的记录的详细信息,但每当我查询数据库时都会抛出错误。

我的查询是:

String call_Status="Open";
String sql="Select * From RMA_Master,Other Where Call_Status='"+call_Status+"'";

StackTrace是:

[Microsoft][ODBC Microsoft Access Driver] The specified field 'Call_Date' could refer to more than one table listed in the FROM clause of your SQL statement.

2 个答案:

答案 0 :(得分:0)

尝试

Select * From RMA_Master as r,Other as o Where r.Call_Status='"+call_Status+"' and o.Call_Status='"+call_Status+"'";

您需要使用别名名称访问call_Status。

相反,您可以选择内部加入

Select * from tableA as a inner join tableB as b on a.call_Status=b.call_Status where a.call_Status=call_Status

答案 1 :(得分:0)

试试这个:

String call_Status="Open";
String sql="Select * From RMA_Master as r,Other as o Where r.Call_Status=o.Call_Status and r.Call_Status='"+call_Status+"'";

如果出现错误,请发布错误以及数据库架构。