Igor
Igor

Reputation: 45

2 table in 1 Column

I need a query to Join 2 tables in 1 column

something like:

SELECT name_cat, name_dog FROM cat, dog;

my results in 1 column

+-------------+
| name_animal |
+-------------+
| cat_1       |
| dog_1       |
| cat_2       |
| cat_3       |
| dog_2       |
+-------------+

Upvotes: 0

Views: 92

Answers (1)

Praveen Kumar Purushothaman
Praveen Kumar Purushothaman

Reputation: 167182

This can be achieved using UNION. Considering the same example, the query should be:

mysql> SELECT `name_cat` FROM `cat` UNION SELECT `name_dog` FROM `dog`;
+---------------+
| `name_cat`    |
+---------------+
| cat_1         |
| dog_1         |
| cat_2         |
| cat_3         |
| dog_2         |
+---------------+    

The example is given here:

mysql> SELECT REPEAT('a',1) UNION SELECT REPEAT('b',10);
+---------------+
| REPEAT('a',1) |
+---------------+
| a             |
| bbbbbbbbbb    |
+---------------+

Hope this helps. :)

Upvotes: 4

Related Questions