简体   繁体   English

使用非重复时仅选择一列

[英]Selecting only one column when using distinct

How can I select only the property_id from this query? 如何从此查询中仅选择property_id

select distinct(property_name), property_id from prop where property_name 
like '%blah%';

I am trying to insert new rows to the table app_prop with the property_id exactly like the query above, so something similar to this: 我正尝试使用与上面的查询完全一样的property_id app_prop向表app_prop插入新行,因此类似于以下内容:

INSERT INTO app_prop (function, PROPERTY_ID)
VALUES('dataq', select distinct(property_name), property_id from prop 
where property_name like '%blah%');
-- only want property_id included NOT property_name --

If you only want the property_id , then select only that. 如果只需要property_id ,则仅选择该property_id

Also: when using a select statement as a source for an insert statement, do not use the values clause. 另外:当使用select语句作为insert语句的源时,请勿使用values子句。

To only insert distinct values for property_id you can use this: 要仅为property_id插入不同的值,可以使用以下命令:

INSERT INTO app_prop (function, PROPERTY_ID)
select distinct 'dataq', property_id 
from prop 
where property_name like '%blah%'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM