开发者

Joining two similar tables in MySQL

开发者 https://www.devze.com 2022-12-27 02:39 出处:网络
I have two tables with similar columns - let\'s say table A with column LABEL_A and table B with column LABEL_B. The data types of LABEL_A and LABEL_B are same.

I have two tables with similar columns - let's say table A with column LABEL_A and table B with column LABEL_B. The data types of LABEL_A and LABEL_B are same.

How can I select LABELs from both tables in a single query? (So开发者_运维问答 the the result of the query contains single column LABEL containing data from LABEL columns of both tables).

EDIT: Can I use such UNION queries in a CURSOR?

Thanks for answers.


Use:

SELECT a.label_a
  FROM TABLE_A a
UNION ALL
SELECT b.label_b
  FROM TABLE_B b

UNION ALL will be faster, but won't remove duplicates if they exist. Use UNION if you want duplicates removed.


Use a UNION:

select LABEL_A as Label from A
union
select LABEL_B as Label from B
0

精彩评论

暂无评论...
验证码 换一张
取 消