IN语句改写EXISTS

-- IN
SELECT
    T1.*
FROM
    role_menu T1
WHERE
    T1.ROLEUUID IN (
        SELECT
            T2.uuid
        FROM
            role T2
        WHERE
            T2.UUID = '1'
    );


-- EXISTS 
SELECT
    T1.*
FROM
    role_menu t1
WHERE
    EXISTS (
        SELECT
            T2.*
        FROM
            role T2
        WHERE
            t1.ROLEUUID = T2.uuid
        AND t2.uuid = '1'
    );

IN 是结果集中删选数据

EXISTS 是判断是否存在

###

两三个条件使用or

多个使用IN

数据量大使用EXISTS

###

posted @ 2018-12-18 11:09  HaniLucky  阅读(2822)  评论(0编辑  收藏  举报