Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 使用与其他表不同的函数更新表_Sql_Sql Server 2008_Distinct - Fatal编程技术网

Sql 使用与其他表不同的函数更新表

Sql 使用与其他表不同的函数更新表,sql,sql-server-2008,distinct,Sql,Sql Server 2008,Distinct,我创建了一个新表,其中包含一些列,所有列都以NULL开头 我有另一个名为“items”的表,其中有一列名为“item\u type”。此列包含许多重复项。我想获取由DISTINCT(item_type)生成的值,并使用它们填充新表中的一个新空列。我试过了,但没能成功: UPDATE new_table SET new_column = DISTINCT(items.item_type) FROM items 我是否需要生成一个新表,然后将这两个表连接起来?最好以这种方式填充该表: INSERT

我创建了一个新表,其中包含一些列,所有列都以NULL开头

我有另一个名为“items”的表,其中有一列名为“item\u type”。此列包含许多重复项。我想获取由
DISTINCT(item_type)
生成的值,并使用它们填充新表中的一个新空列。我试过了,但没能成功:

UPDATE new_table
SET new_column = DISTINCT(items.item_type)
FROM items

我是否需要生成一个新表,然后将这两个表连接起来?

最好以这种方式填充该表:

INSERT INTO new_table(new_column)
SELECT DISTINCT(items.item_type)
FROM items


如果表已填充-您需要提供一些连接这些表的行为,假设新表为空:

INSERT new_table
SELECT DISTINCT item_type
FROM items

您正在使用什么RDBMS?。另外,您如何将旧表上的
与新表关联起来?其余的列是什么?