日期:2014-05-17  浏览次数:20855 次

如何能把下面两个sql写成一个sql,麻烦大家
SELECT   DISTINCT   A.MEIGARA_NAME
    FROM   MEIGARA_INFO2   A,   IMG_INFO2   B,   BK003_INFO2   C
  WHERE   A.MEIGARA   =   C.MEIGARA
      AND   B.M_ID   =   C.M_ID
      AND   B.READ_YMD   =   C.READ_YMD
      AND   B.READ_M_ID   =   C.READ_M_ID
      AND   B.TUBAN   =   C.TUBAN
      AND   B.KI_BAN   =   C.KI_BAN
      AND   B.IREI_FLAG   =   C.IREI_FLAG
      AND   B.STATUS   =   '06 '      
     
  SELECT   DISTINCT   A.MEIGARA_NAME
      FROM   MEIGARA_INFO2   A,   IMG_INFO2   B,   KC005_INFO2   D
    WHERE   A.MEIGARA   =   D.MEIGARA
        AND   B.M_ID   =   D.M_ID
        AND   B.READ_YMD   =   D.READ_YMD
        AND   B.READ_M_ID   =   D.READ_M_ID
        AND   B.TUBAN   =   D.TUBAN
        AND   B.KI_BAN   =   D.KI_BAN
        AND   B.IREI_FLAG   =   D.IREI_FLAG
        AND   B.STATUS   =   '06 '

------解决方案--------------------
SELECT DISTINCT A.MEIGARA_NAME
FROM MEIGARA_INFO2 A, IMG_INFO2 B, BK003_INFO2 C
WHERE A.MEIGARA = C.MEIGARA
AND B.M_ID = C.M_ID
AND B.READ_YMD = C.READ_YMD
AND B.READ_M_ID = C.READ_M_ID
AND B.TUBAN = C.TUBAN
AND B.KI_BAN = C.KI_BAN
AND B.IREI_FLAG = C.IREI_FLAG
AND B.STATUS = '06 '
UNION --合并,或者UNION ALL
SELECT DISTINCT A.MEIGARA_NAME
FROM MEIGARA_INFO2 A, IMG_INFO2 B, KC005_INFO2 D
WHERE A.MEIGARA = D.MEIGARA
AND B.M_ID = D.M_ID
AND B.READ_YMD = D.READ_YMD
AND B.READ_M_ID = D.READ_M_ID
AND B.TUBAN = D.TUBAN
AND B.KI_BAN = D.KI_BAN
AND B.IREI_FLAG = D.IREI_FLAG
AND B.STATUS = '06 '