0

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.

3
  • Please show the column structure of both tables and also what is your expected output ? Commented Oct 31, 2014 at 5:41
  • if there is no relation, then just do separate select query Commented Oct 31, 2014 at 5:42
  • Right now you are creating a full Cartesian product. Commented Oct 31, 2014 at 5:43

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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

1 Comment

thanKz paxdiablo... second one works for me when used with UNION ALL

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.