简体   繁体   English

SQL 查询从一个表中获取不同的结果并将这些结果与表中的另一列匹配

[英]SQL Query to get distinct results from one table and match those results to the another column in the table

I have an SQL table with product names in one column and a product category in another column.我有一个 SQL 表,其中一列包含产品名称,另一列包含产品类别。 So each product belongs to a specific category.所以每个产品都属于一个特定的类别。 I am trying to figure out an sql command that will return distinct values from the product name column but will also display the product category each product belongs to.我试图找出一个 sql 命令,它将从产品名称列返回不同的值,但也会显示每个产品所属的产品类别。 Any ideas?有任何想法吗?

你可以这样试试

  SELECT Distinct([ProductName]),[ProductCategeory] FROM [DB].[dbo].[tblProduct]

暂无
暂无

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

相关问题 SQL从一个表中返回聚合结果作为查询中的列 - SQL returning aggregated results from one table as a column in a query SQL从一个表列中选择一个最小值,然后将结果插入一个SQL语句的另一个表列中 - Sql Select a minimum value from a table column and insert the results in another table column in one SQL statement SQL Server:将不同结果连接到匹配表的单个列中 - SQL Server : concatenate distinct results into single column from matched table 使用 SQL 表的一列中的结果来搜索另一个表 - Use results in one column on a SQL table to search another table sql查询从审计表中获取数据,其中列匹配一个值,但不匹配另一个 - sql query to get data from an audit table where column match one value, but not another 将 SELECT 列表中一个表的查询结果用于另一个表 - Using query results from one table in the SELECT list for another table 通过与另一个字段匹配来过滤列表1并从表2获得结果 - Filter column table 1 and get results from table 2 by matching with another field 当同一表的另一列中存在多于1个不同值时,用于从一列中计算不同值的SQL查询 - SQL Query for Counting Distinct Values From One Column When More Than 1 Distinct Value exists in Another Column in the same table SQL-根据另一个查询的结果创建联接/查询。 Join表将来自另一个查询的结果 - SQL - Create a join / query based on the results of another query. The Join table would be from the results of another query sql从一列获取结果,另一列的名称 - sql get results from one column with the name of another column
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM