Combining two similar tables in MySQL

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

How can I select LABELs from both tables in one query? (Thus, the query result contains one LABEL column containing data from the LABEL columns of both tables.)

EDIT: can I use UNION queries like this in CURSOR?

Thanks for answers.

+2


a source to share


2 answers


Using:

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 to remove duplicates.

+4


a source


Use UNION

:



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

      

+3


a source







All Articles