我有一个SQL表数据如下
我想显示产品的单条记录
例子
90792 Amlaan-Hi-Power .............. Show only 1 record when there are 2 record
90793 Amlaan-Neutral .............. show only 1 record when there are 2 record
90794 Amlaan-Phosphate free .........show only 1 record when there are 2 record
90801 Acetone .......................show only 1 record when there are 2 record
90901 Acetanilide ...................show only 1 record when there is 1 record
我可以使用内部联接来做到这一点吗
我知道
select distinct product from product ORDER BY `product`.`product` DESC
将选择不同的(唯一的)产品代码,并且只选择一个字段,即产品,但对如何使用 SQL 语句获取其他信息感到困惑
但导致重复记录或同一张表......................................................
最佳答案
看起来您的重复行因包装中产品的数量而异。
您可以只显示产品和名称
SELECT DISTINCT product, name
FROM product
如果您还想处理数量,那就有点棘手了。这可能有效:它将所有产品代码放在一行中。
SELECT product,
GROUP_CONCAT(product_code ORDER BY product_code) product_codes,
name
FROM product
GROUP BY product, name
自连接对于这个应用程序没有多大意义。
关于mysql - 自内连接获取单条记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28765976/