반응형
  1. /**********************************************************************************************
    -- Title : [2k5] UNION/INTERSECT/EXCEPT의 다른 SQL 문과의 연계 가이드
    -- Reference : dbrang.com, mcpworld.com
    -- Key word : union intersect except into order by group by having
    **********************************************************************************************/
    -- UNION/INTERSECT/EXCEPT의 다른 T-SQL 문과의 연계 가이드
    drop table t1,t2;
    go
  2. create table t1 (a int, b int, c char(1));
    create table t2 (a int, b int, c char(1));
    go
  3. insert into t1 values (1,1,'a');
    insert into t1 values (1,2,'a');
    insert into t1 values (2,1,'a');
    insert into t1 values (2,2,'a');
  4. insert into t2 values (1,1,'a');
    insert into t2 values (2,2,'a');
    go
    -- into 절은 첫번째 쿼리에 기술
    select a, b into #ttt from t1
    intersect
    select a, b from t2;
    go
  5. select * from #ttt
    go
  6. -- order by 절은 마지막 쿼리 이후에 기술
    select a, b from t1
    except
    select a, b from t2
    order by b
    go
  7. -- GROUP BY와 HAVING 절은 개별 쿼리에만 사용 가능하며
    -- 최종 결과 집합에는 영향을 미치지 않음
    select a,b from t2
    intersect
    select a,b from t1;
    go
  8. select a,b from t2
    group by a,b
    intersect
    select a,b from t1;
    go
반응형

+ Recent posts