我有2个表,表A和表B.我必须按如下方式显示A的值:
select * from A
where EntityId = 26039 and EntityTypeId = 'REQUEST'
然后,从B我想要检索如下值:
select OrderRequestTaskId from B
where OrderRequestId = 26039
这可能会提供0或更多OrderRequestTaskId。如果此查询返回1,2,3的OrderRequestTaskId值,那么我想从表A中显示它们,如下所示:
select * from A
where (EntityId = 1 and EntityTypeId = 'TASK')
or (EntityId = 2 and EntityTypeId = 'TASK')
or (EntityId = 3 and EntityTypeId = 'TASK')
简而言之,select语句现在如下:
select * from A
where (EntityId = 26039 and EntityTypeId = 'REQUEST')
or (EntityId = 1 and EntityTypeId = 'TASK' )
or ( EntityId = 2 and EntityTypeId = 'TASK')
or( EntityId = 3 and EntityTypeId = 'TASK')
我不确定如何在存储过程中执行此操作,以便将所有4行作为输出。我可以存储语句
的输出select OrderRequestTaskId from B
where OrderRequestId = 26039
然后用它来构建最终的select语句?
答案 0 :(得分:1)
您只需要使用Inner Join 它看起来像
select a.* from TableA a
Inner Join TableB b
on a.EntityID=b.OrderRequestId
- 条件(如果有的话)
where OrderRequestId = 26039