我试图在PostgreSQL中仅为查询选择不同的行。
我有以下代码:
INSERT INTO Products
("Unique ID","Manufacturer Name","Manufacturer Part Number","Packaging UOM")
SELECT
'Unique ID',
'Manufacturer Name',
'Manufacturer Part Number',
'Packaging UOM'
FROM
All_Catalogs
当我用Select Selectinin替换Select时,我最终只是标题表All_Catalogs的标题,而不是所有的值。
我不想选择所有内容并删除唯一ID的副本,我最初只会使用唯一的ID'
来抓取行我感谢任何帮助/建议。
尝试在线查看时: Confusion about SELECT DISTINCT in SQL - 这表明我得到了“非int错误”组。所以它对我不起作用 SELECT DISTINCT values and INSERT INTO table - 这再次提示我得到非int错误的组
答案 0 :(得分:0)
此查询仅选择UniqueID
All_Catalogs
行
INSERT INTO Products
("Unique ID","Manufacturer Name","Manufacturer Part Number","Packaging UOM")
SELECT
"Unique ID",
"Manufacturer Name",
"Manufacturer Part Number",
"Packaging UOM"
FROM
All_Catalogs
WHERE "Unique ID" IN (SELECT "Unique ID"
FROM All_Catalogs
GROUP BY "Unique ID"
HAVING COUNT(*) = 1)