在MySQL中联接两个相似的表 [英] Joining two similar tables in MySQL

查看:100
本文介绍了在MySQL中联接两个相似的表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个表的列相似-假设表A的列为LABEL_A 和表B的列LABEL_B. LABEL_A和LABEL_B的数据类型相同.

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.

如何在单个查询中从两个表中选择标签? (因此,查询结果包含单个列LABEL,其中包含两个表的LABEL列中的数据.)

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).

我可以在游标中使用此类UNION查询吗?

Can I use such UNION queries in a CURSOR?

感谢答案.

推荐答案

使用:

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

UNION ALL将更快,但是如果存在重复项,则不会删除重复项.如果要删除重复项,请使用UNION.

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

这篇关于在MySQL中联接两个相似的表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆