我有两个select语句,我想要grep两个表的结果,然后显示一个下拉框。我可以为每个SELECT
语句执行此操作,但我无法同时从两个语句中进行选择。
以下是我的2个SELECT语句:
string loggedIn= (User.Identity.Name);
SELECT DISTINCT ReportTitle from HRPastReports WHERE [username] LIKE '%" + loggedIn + "%'";
SELECT DISTINCT ReportTitle from FinancePastReports WHERE [username] LIKE '%" + loggedIn+ "%'";
如何将SELECT
语句合并为一个语句?
谢谢
答案 0 :(得分:2)
您只能通过UNION
执行此操作,因为您引用了两个不同的表
SELECT DISTINCT ReportTitle from HRPastReports WHERE [username] LIKE '%" + loggedIn + "%'";
UNION
SELECT DISTINCT ReportTitle from FinancePastReports WHERE [username] LIKE '%" + loggedIn+ "%'";
答案 1 :(得分:1)
您可以使用UNION
运算符
SELECT DISTINCT ReportTitle from HRPastReports WHERE [username] LIKE '%" + loggedIn + "%'";
union all
SELECT DISTINCT ReportTitle from FinancePastReports WHERE [username] LIKE '%" + loggedIn+ "%'";