SELECT image_name
, document_id
, document_name
, document_category
, workflow_state_name
, container_name
, modelyear
, build_phase
, revision_level
, owner
, container_id
, document_description description
FROM container_document_view
WHERE document_id IS NOT NULL
UNION
SELECT DISTINCT 'icon_folder.gif' image_name
, container_id document_id
, container_name document_name
, '' document_category
, workflow_state_name
, container_name
, modelyear
, build_phase
, revision_level
, owner
, container_id
, container_description description
FROM container_details_view
WHERE container_id NOT IN (
SELECT container_id
FROM document
)
UNION
SELECT image_name
, document_id
, document_name
, document_category
, workflow_state_name
, container_name
, modelyear
, build_phase
, revision_level
, owner
, container_id
, document_description description
FROM container_link_view
WHERE container_id IS NOT NULL
ORDER BY container_name, container_id, document_name, modelyear, build_phase, revision_level
答案 0 :(得分:0)
你为什么要避免它?
如果速度过慢,您可能会检查是否可以更改为UNION ALL
,这样可以避免代价高昂的DISTINCT
。
另外,当您将NOT IN
重写为NOT EXISTS
时,{{1}}可能会更有效。