Chinnu
Chinnu

Reputation: 117

MYSQL join two different columns from two different table as single column

I have two tables with no relation between them. The following is a query I've tried:

SELECT table1.columnName, table2.columnName AS newColumn
FROM table1, table2.

I am unable to get the results I need.

Upvotes: 0

Views: 5685

Answers (2)

Shailesh Singh
Shailesh Singh

Reputation: 21

There can be several queries depends on scenario. However, if you want to join two different columns of two different tables into a single column without WHERE then you can do like:

SELECT CONCAT( table1.col1 , table2.col2) AS colName FROM Table table1,Table table2.

Upvotes: 2

paxdiablo
paxdiablo

Reputation: 881453

Assuming you want the columns combined into a single column, without a where clause, that's going to give you a (probably larger than you want) Cartesian product, but you can do it with something like:

select concat (tbl1.col1, tbl2.col2) from tbl1, tbl2

If you want a single column with values from both tables (rather than concatenating them), just use something like:

select col1 as col from tbl1
union
select col2 as col from tbl2

Upvotes: 1

Related Questions