this question is based on
SQL 2008 R2 CTE syntax error in a SELECT statement
On SQL server 2008, I need to get a new table by selecting two columns from two different tables.
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. The cte has no column of "address". the another_table has no column of id_num.
for each address, I need to associate all id_num in cte to the address
Any help would be appreciated.
If this isn't a join, and you want to associate all id_nums to all addresses, then use:
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:
where cte.field1 = address.field1
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.