![](/img/trans.png)
[英]get a new table from two tables based on the columns' values in a table in SQL server:
[英]SQL server 2008, get a new table by selecting two columns from two different tables that do not share same column information
这个问题是基于
在SQL Server 2008上,我需要通过从两个不同的表中选择两个列来获取一个新表。
address (from another_table) id_num (from a cte created by me)
city_1 65
city_1 36
city_2 65
city_2 36
city_3 65
city_3 36
假设id_num只有65和36两个值。 CTE没有“地址”列。 another_table没有id_num列。
对于每个地址,我需要将cte中的所有id_num关联到该地址
任何帮助,将不胜感激。
如果这不是联接,并且您要将所有id_nums与所有地址相关联,请使用:
select distinct address, id_num
from another_table, cte
如果希望将id_num仅与符合某些条件的地址相关联,请添加where子句:
where cte.field1 = address.field1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.