SQL 连接两个没有键/关系的表

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1797785/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 04:32:49  来源:igfitidea点击:

SQL join two tables without keys/relations

sqljoin

提问by dirol

I have two tables, one of them has weeks of year, and the second table has categories. I need to create a table that contains each week and each category, but there's no fields/keys that intersect in two tables:

我有两个表,其中一个包含一年中的周数,第二个表包含类别。我需要创建一个包含每周和每个类别的表,但没有在两个表中相交的字段/键:

Table 1:

表格1:

week1
week2
week3
week4

Table 2:

表 2:

Cat1
Cat2

Resulting table:

结果表:

week1 cat1
week1 cat2
week2 cat1
week2 cat2
...
week4 cat1
week4 cat2

I'd like to do this without using many cursors/looping.

我想在不使用很多游标/循环的情况下做到这一点。

回答by Matthew Jones

SELECT * FROM Table1 CROSS JOIN Table2

This will get you every combination of all columns from Table1 and Table2.

这将为您提供 Table1 和 Table2 中所有列的所有组合。

回答by Valentin Golev

Have you tried just

你有没有试过

 SELECT * FROM table1, table2