[英]SQL server 2008, get a new table by selecting two columns from two different tables that do not share same column information
this question is based on 这个问题是基于
SQL 2008 R2 CTE syntax error in a SELECT statement SELECT语句中的SQL 2008 R2 CTE语法错误
On SQL server 2008, I need to get a new table by selecting two columns from two different tables. 在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
Suppose that id_num has only 65 and 36 two values. 假设id_num只有65和36两个值。 The cte has no column of "address".
CTE没有“地址”列。 the another_table has no column of id_num.
another_table没有id_num列。
for each address, I need to associate all id_num in cte to the address 对于每个地址,我需要将cte中的所有id_num关联到该地址
Any help would be appreciated. 任何帮助,将不胜感激。
If this isn't a join, and you want to associate all id_nums to all addresses, then use: 如果这不是联接,并且您要将所有id_nums与所有地址相关联,请使用:
select distinct address, id_num
from another_table, cte
If you want the id_num to only be associated with addresses that match some criteria add a where clause: 如果希望将id_num仅与符合某些条件的地址相关联,请添加where子句:
where cte.field1 = address.field1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.