SELECT UNION


UNION, INERSECT, EXCEPT를 활용한 복합 쿼리

합집합: UNION, UNION ALL
교집합: INTERSECT
차집합: EXCEPT

테스트 테이터 입력: Redis 명령으로 입력

Example

명령>mset myval10 value10 myval30 value30 myval50 value50 myval70 value70
결과>OK

SQL Insert 문으로 입력

Example

명령> insert into string values('myval10','value10'), ('myval30','value30'), ('myval50','value50'),
('myval70','value70');
결과>4 inserted

UNION ALL

Example

명령>select value from string.mystr* union all select value from string.myval*;   opcode
결과> 0) value
1) value10
2) value30
3) value50
4) value20
5) value40
6) value10
7) value30
8) value50
9) value70

UNION

Example

명령>select value from string.mystr* union select value from string.myval*;   opcode
결과> 0) value
1) value10
2) value20
3) value30
4) value40
5) value50
6) value70

다른 데이터타입 간 UNION

Example

명령>select value from string.mystr* union all select value from list.mylist3;   opcode
결과>   0) value
  1) value10
  2) value30
  3) value50
  4) value20
  5) value40
  6) AAA
  7) BBB
  8) CCC
  9) DDD
10) EEE

숫자와 문자열 간 UNION

Example

명령>select value from set.myset2 union select value from zset.myzset1;   opcode
결과>   0) value
  1) 10
  2) 20
  3) 30
  4) 40
  5) 50
  6) value10
  7) value20
  8) value30
  9) value40
10) value50

INTERSECT

Example

명령>select value from string.mystr* intersect select value from string.myval*;   opcode
결과> 0) value
1) value10
2) value30
3) value50
명령>select value from zset.myzset2 intersect select value from set.myset1;   opcode
결과> 0) value
1) mem10
2) mem20
3) mem30
4) mem40
5) mem50

EXCEPT

Example

명령>select value from string.mystr* except select value from string.myval*;   opcode
결과> 0) value
1) value20
2) value40
명령>select value from zset.myzset2 except select value from set.myset1;   opcode
결과> 0) value
1) mem100
2) mem60
3) mem70
4) mem80
5) mem90

OPCODE


select value from string.mystr* union all select value from string.myval*;

select value from string.mystr* union select value from string.myval*;

select value from string.mystr* union all select value from list.mylist3;

select value from set.myset2 union select value from zset.myzset1;

select value from string.mystr* intersect select value from string.myval*;

select value from zset.myzset2 intersect select value from set.myset1;

select value from string.mystr* except select value from string.myval*;

select value from zset.myzset2 except select value from set.myset1;


<< Select Subquery Select Union Functions >>

Email 답글이 올라오면 이메일로 알려드리겠습니다.