我有两个表reconciliation_data
和inventory_transaction
。
两个表都有event_id
,status
,user_id
。 inventory_transaction.id
是inventory_transaction_id
中作为reconciliation_data
的外键。现在,我已根据以下两个条件从两个表中获取数据
1) Join both tables if inventory_transaction_id in reconciliation_data is not null.
2) If status in reconciliation_data is 'NEW_FOUND', then inventory_transaction_id in reconciliation_data will be null, fetch the data from only reconciliation_data for that particular event_id and user_id.
我希望有一个没有联合的查询,可以达到目的。
我尝试使用联合,但是我们不能使用联合,因为out框架不支持联合。
select r.id, it.status, r.physical_inventory_status, it.asset_id, r.inventory_id, r.event_id, r.sfl_user_id
from rbxdev.inventory_transaction it
left join rbxdev.reconciliation_data r on r.inventory_transaction_id = it.id and r.sfl_user_id = 3
where it.event_id = 29
union
select r1.id, r1.physical_inventory_status, r1.physical_inventory_status, r1.inventory_id, r1.inventory_id, r1.event_id, r1.sfl_user_id
from rbxdev.reconciliation_data r1
where r1.physical_inventory_status = 'NEW_FOUND' and r1.event_id = 29 and r1.sfl_user_id = 3;
期望的是没有联合的单个查询,可以解决此问题。