How to combine two unrelated tables in Mysql

為{幸葍}努か 提交于 2019-12-23 10:56:39

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!