3

我是 sql 新手,需要一点帮助。我有union3 个表的查询。我有一个虚拟列,所以我可以知道每行来自哪个表。我希望能够过滤此虚拟列以仅显示特定表中的行。

我正在使用 Microsoft Access,这是我目前所拥有的:

SELECT Table1 as Table_Name, Table1.1  
FROM Table1  
UNION ALL  
SELECT Table2 as Table_Name, Table2.1  
FROM Table2  
UNION ALL  
SELECT Table3 as Table_Name, Table3.1  
FROM Table3  
UNION ALL  
WHERE Table_Name = Form1.TextBox  
ORDER BY Table1.1;

我正在尝试将其链接到表单上的列表框,然后有一些文本框来过滤结果。

4

1 回答 1

6

怎么样:

SELECT * FROM
( SELECT Table1 as Table_Name, Table1.1
FROM Table1
UNION ALL
SELECT Table2 as Table_Name, Table2.1
FROM Table2
UNION ALL
SELECT Table3 as Table_Name, Table3.1
FROM Table3 ) q
WHERE Table_Name = Forms!Form1!TextBox
ORDER BY Table1.1;

见:http ://access.mvps.org/access/forms/frm0031.htm

于 2013-02-14T12:21:56.307 回答