【发布时间】:2018-07-23 01:25:09
【问题描述】:
我正在尝试在 Oracle 查询中使用连接,但我不确定如何返回带有或不带有该连接条件的所有记录。以下是查询
Select req.barcode,contact.barcode,inst.barcode from entity_view req
join entity_association_view assreq ON assreq.entity_id_1 = req.entity_id
join entity_view contact on assreq.entity_id_2 = contact.entity_id and contact.entity_type_name = 'CONTACT'
join entity_association_view assins ON assins.entity_id_2 = contact.entity_id
join entity_view inst on assins.entity_id_1 = inst.entity_id and inst.entity_type_name = 'INSTITUTION'
where req.entity_type_name = 'REQUEST'
这里它返回只有联系人的请求。但我也想要没有联系人的请求。我不熟悉子查询,我应该在这里使用它来获取所有有或没有联系的记录
我也使用了左连接,但它带来了像
这样的记录Select distinct req.barcode,contact.barcode,inst.barcode from entity_view req
left join entity_association_view assreq ON assreq.entity_id_1 = req.entity_id
left join entity_view contact on assreq.entity_id_2 = contact.entity_id and contact.entity_type_name = 'CONTACT'
left join entity_association_view assins ON assins.entity_id_2 = contact.entity_id
left join entity_view inst on assins.entity_id_1 = inst.entity_id and inst.entity_type_name = 'INSTITUTION'
where req.entity_type_name = 'REQUEST' and req.barcode = 'GET0127' order by req.barcode
【问题讨论】:
-
试试
LEFT JOIN -
将所有
joins 更改为left joins。 -
看起来像一个没有联系我的请求
-
@GordonLinoff 我已经尝试过左连接,但它带来了我在屏幕截图中放入的记录。它应该只有 GET0127 CON001 INS002
-
@Paparazzi 我无法让你感到抱歉