我在查询中苦苦挣扎:
select bl.REF_CORP_ID as [Dept id] , bl.REF_CORE_BUDGET_ID, rc.Col_1 , bl.SubmittedDate as [Created Date time] , bl.APPROVED_BY , bl.APPROVED_DATETIME , bl.APPROVAL_FROM
from TABLE1 bl right join TABLE2 rc on bl.REF_CORP_ID =rc.ref_corp_id AND bl.REF_CORE_BUDGET_ID =1
group by bl.REF_CORP_ID , REF_CORE_BUDGET_ID , Col_1 , SubmittedDate , APPROVED_BY , APPROVED_DATETIME , APPROVAL_FROM
导致以下方式:
1 1 IT 2013-07-10 19:29:40.700
1 1 IT 2013-07-10 19:29:40.700
2 1 Sales NULL
2 1 Sales NULL
4 1 HR 2013-07-10 19:32:21.720
4 1 HR 2013-07-10 19:32:21.720
6 1 management 2013-07-10 20:24:29.890
但这是我想要的:
1 1 IT 2013-07-10 19:29:40.700
2 1 Sales NULL
4 1 HR 2013-07-10 19:32:21.720
6 1 management 2013-07-10 20:24:29.890
我有两个表,我在其中应用了内部联接,但在一个表中有相同的记录,第二个表只有部门信息和部门名称