问题
There are two tables that are not related to each other(No foreign keys). How to show them together in MySQL?
TABLE1
TABLE2
Result
回答1:
You can use this too:
SELECT t2.date, t1.name
FROM table1 t1
CROSS JOIN table2 t2
回答2:
Try This..
SELECT t2.date, t1.name FROM table1 t1, table2 t2 ORDER BY t1.name ASC
回答3:
Try simply
SELECT t2.date, t1.name FROM table1 t1, table2 t2
回答4:
Try this: SELECT DATE, NAME FROM TABLE1, TABLE2
回答5:
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.
来源:https://stackoverflow.com/questions/17630227/how-to-combine-two-unrelated-tables-in-mysql