其中函数在联合查询中的虚拟列上

时间:2013-02-14 10:38:01

标签: sql ms-access union

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

我正在使用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;

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

1 个答案:

答案 0 :(得分: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