1
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
4

1 回答 1

0

为什么要避免它?

如果速度太慢,您可能会检查是否可以改为UNION ALL改为,这避免了昂贵的DISTINCT.

此外,NOT IN当您将其重写为NOT EXISTS.

于 2013-08-27T09:13:15.667 回答