Question

There are two tables that are not related to each other(No foreign keys). How to show them together in MySQL?

TABLE1

enter image description here

TABLE2

enter image description here

Result

enter image description here

Was it helpful?

Solution

You can use this too:

SELECT t2.date, t1.name
FROM table1 t1
CROSS JOIN table2 t2

OTHER TIPS

Try This..

 SELECT t2.date, t1.name FROM table1 t1, table2 t2 ORDER BY t1.name ASC

Try simply

SELECT t2.date, t1.name FROM table1 t1, table2 t2

Try this: SELECT DATE, NAME FROM TABLE1, TABLE2

None of those will work.

If you want to learn how to do this properly, I'd suggest you take a look at this http://blog.codinghorror.com/a-visual-explanation-of-sql-joins/

CROSS JOIN is not what you are looking for.

SQL will not be able to process this query. What I suggest you do is to get both record sets with two different queries and then sort them by the field you want, using PHP/Python/C or whatever the code your app is based on. Just don't leave that to the MySQL server because it can't.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top