일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
Tags
- plugin
- Elasticsearch
- analyzer test
- Mac
- licence delete curl
- 900gle
- MySQL
- 차트
- matplotlib
- Java
- License
- 파이썬
- API
- Python
- token filter test
- zip 파일 암호화
- Kafka
- aggregation
- sort
- aggs
- Test
- docker
- high level client
- license delete
- flask
- query
- ELASTIC
- springboot
- TensorFlow
- zip 암호화
Archives
- Today
- Total
개발잡부
[MySql] Union Query 본문
반응형
Sample
CREATE TABLE `union_test_a` (
`id` bigint NOT NULL AUTO_INCREMENT COMMENT 'id',
`item_number` varchar(25) NOT NULL COMMENT '상품번호',
`ranking` varchar(2) NOT NULL DEFAULT '1' COMMENT '우선순위',
PRIMARY KEY (`id`),
KEY `idx_sch_edlp` (`item_number`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='TEST_A';
CREATE TABLE `union_test_b` (
`id` bigint NOT NULL AUTO_INCREMENT COMMENT 'id',
`item_no` varchar(25) NOT NULL COMMENT '상품번호',
`ranking` varchar(2) NOT NULL DEFAULT '1' COMMENT '우선순위',
PRIMARY KEY (`id`),
KEY `idx_sch_edlp` (`item_no`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='TEST_B';
INSERT INTO `doo`.`union_test_a` (`item_number`, `ranking`) VALUES ('292939882','1');
INSERT INTO `doo`.`union_test_a` (`item_number`, `ranking`) VALUES ('123334234','2');
INSERT INTO `doo`.`union_test_a` (`item_number`, `ranking`) VALUES ('675866456','3');
INSERT INTO `doo`.`union_test_b` (`item_no`, `ranking`) VALUES ('986756745','4');
INSERT INTO `doo`.`union_test_b` (`item_no`, `ranking`) VALUES ('196456435','5');
INSERT INTO `doo`.`union_test_b` (`item_no`, `ranking`) VALUES ('454345235','6');
INSERT INTO `doo`.`union_test_b` (`item_no`, `ranking`) VALUES ('856456456','7');
SELECT item_number FROM doo.union_test_a
union
SELECT item_no as item_number FROM doo.union_test_b;
-- 중복허용
SELECT item_number FROM doo.union_test_a
union all
SELECT item_no as item_number FROM doo.union_test_b;
반응형
'Database' 카테고리의 다른 글
[mysql] left join 안에서 group_concat (0) | 2023.03.14 |
---|---|
[mysql] PRIMARY KEY, UNIQUE KEY (0) | 2022.04.23 |
[Mysql] View (0) | 2022.04.01 |
[Mysql] Procedure (0) | 2022.04.01 |
[MySql] Event Scheduler (0) | 2022.04.01 |
Comments