SQL连接两个没有键/关系的表 [英] SQL join two tables without keys/relations

查看:680
本文介绍了SQL连接两个没有键/关系的表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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:

表1:

week1
week2
week3
week4

表2:

Cat1
Cat2

结果表:

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

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

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

推荐答案

SELECT * FROM Table1 CROSS JOIN Table2

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

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

这篇关于SQL连接两个没有键/关系的表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆