我有2个select语句,我想对两个表的结果进行grep并显示然后显示一个下拉框。我可以针对每个SELECT语句执行此操作,但是无法同时从两者中进行选择。
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语句合并为一个语句?
谢谢
您只能通过UNION引用两个不同的表来执行此操作
UNION
SELECT DISTINCT ReportTitle from HRPastReports WHERE [username] LIKE '%" + loggedIn + "%'"; UNION SELECT DISTINCT ReportTitle from FinancePastReports WHERE [username] LIKE '%" + loggedIn+ "%'";