[英]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.