SELECT
m.provider_id,
m.provider_name,
p.purchase_order_code,
NULL AS purchase_order_sample_code,
p.provider_id AS provider_order
FROM mst_provider AS m
LEFT JOIN trx_purchase_order AS p
ON (m.provider_id = p.provider_id)
WHERE p.provider_id != NULL
UNION
SELECT
m.provider_id,
m.provider_name,
p.purchase_order_code,
NULL AS purchase_order_sample_code,
p.provider_id AS provider_order
FROM mst_provider AS m
RIGHT JOIN trx_purchase_order AS p
ON (m.provider_id = p.provider_id)
UNION
SELECT
m.provider_id,
m.provider_name,
NULL,
s.purchase_order_sample_code,
s.provider_id
FROM mst_provider AS m
RIGHT JOIN trx_purchase_order_sample AS s
ON (s.provider_id = m.provider_id)
SELECT *
FROM (
SELECT m.provider_id,
m.provider_name,
p.purchase_order_code,
NULL AS purchase_order_sample_code,
p.provider_id AS provider_order
FROM mst_provider AS m
LEFT JOIN trx_purchase_order AS p
ON (m.provider_id = p.provider_id)
UNION
SELECT m.provider_id,
m.provider_name,
p.purchase_order_code,
NULL AS purchase_order_sample_code,
p.provider_id AS provider_order
FROM mst_provider AS m
RIGHT JOIN trx_purchase_order AS p
ON (m.provider_id = p.provider_id)
UNION
SELECT m.provider_id,
m.provider_name,
NULL,
s.purchase_order_sample_code,
s.provider_id
FROM mst_provider AS m
RIGHT JOIN trx_purchase_order_sample AS s
ON (s.provider_id = m.provider_id)
) _temp
WHERE provider_order IS NOT NULL
3条答案
按热度按时间3df52oht1#
不能仅删除行中的该字段。但是,只需使用where子句过滤掉具有空值的记录,就可以除去整行。
http://sqlfiddle.com/#!9/f77862/42电话
zbsbpyhn2#
我假设你想过滤提供者的顺序是空的?
我将整个查询 Package 为一个子查询,并在末尾放置一个where子句,只返回provider\u order不为null的记录。
http://sqlfiddle.com/#!9/f77862/50/0号
uqdfh47h3#
“删除”是什么意思?删除整行或只是按顺序显示除null以外的其他内容。如果以后要查找,那么可以使用coalesce
编辑:仅对小提琴进行了更改:http://sqlfiddle.com/#!9/f77862/46电话