Oracle - UNION, UNION ALL

*** UNION ***
두 테이블을 결합한 결과를 반환하는데 중복되지 않는 값들만 반환.
결과는 정렬되어서 반환.


*** UNION ALL ***
두 테이블을 결합한 결과를 반환하는데 중복되는 값들도 모두 반환.


ex) 
TABLE_1                           TABLE_2
---------                         ---------
COL_A                              COL_A
---------                         ---------
1                                         3
2                                         2
3                                         1

select COL_A from TABLE_!
union
select COL_A from TABLE_2
=> 결과
1
2
3

select COL_A from TABLE_!
union all
select COL_A from TABLE_2
=> 결과
1
2
3
3
2
1

MyBatis 동적 쿼리 - choose

*** choose 문 ***
스위치 구문과 비슷. 여러 조건을 순서대로 체크하여 해당하는 조건의 구문을 추가.
해당되는 조건이 없을 경우 otherwise에 해당하는 구문을 추가

ex)
<select id="testSql" parameterType="hashmap" resultType="hashmap">
    select
        ID, NAME
    from
        T_TEST A
    where USE_YN = 'Y'
    <choose>       
        <when test="type == 'A' ">
            and TYPE = 'A'
        </when>       
        <when test="type == 'B' ">
            and TYPE = 'B'
        </when>
        <otherwise>
            and TYPE = 'C'
        </otherwise>
    </choose>
</select>

interface 형식
@Select("<script>"
    + "select "
    + " ID, NAME "
    + "from T_TEST A "
    + "where USE_YN = 'Y' "
    + " <choose>"
    + "   <when test=\"type == 'A'\"> TYPE = 'A' </when>"
    + "   <when test=\"type == 'B'\"> TYPE = 'B' </when>"
    + "   <otherwise> TYPE = 'C' </otherwise>"
    + " </choose>"
    + "</script> ")
List<HashMap> select(@Param("type")String type);

MyBatis 동적 쿼리 - if

*** if 문 ***
조건을 만족하는 경우 추가

ex) type 값이 null이 아니고, 빈값이 아닐때 조건에 추가
xml 형식
<select id="testSql" parameterType="hashmap" resultType="hashmap">
    select
        ID, NAME
    from
        T_TEST A
    where USE_YN = 'Y'
    <if test="type != null and type != ''"> and TYPE = #{type} </if>
</select>

interface 형식
@Select("<script>"
    + "select "
    + " ID, NAME "
    + "from T_TEST A "
    + "where USE_YN = 'Y' "
    + "<if test=\"type != null and type != ''\"> and TYPE = #{type} </if>"
    + "</script> ")
List<HashMap> select(@Param("type")String type);