将表中的colums组合返回多次相同的记录

时间:2016-08-09 09:45:11

标签: sql sqlite join

我有2个表INVENTORYPRODUCTS,我想要选择INVENTORY的一些列和PRODUCTS中的一列。我写道:

SELECT INVENTORY.product, INVENTORY.version, PRODUCTS.customer
FROM INVENTORY
INNER JOIN PRODUCTS ON
INVENTORY.product = PRODUCTS.product AND INVENTORY.version= PRODUCTS.version

我得到了相同记录的多次..我是如何解决的?

1 个答案:

答案 0 :(得分:0)

简单分明或分组:

SELECT DISTINCT INVENTORY.product, INVENTORY.version, PRODUCTS.customer
FROM INVENTORY
INNER JOIN PRODUCTS ON
INVENTORY.product = PRODUCTS.product AND INVENTORY.version= PRODUCTS.version

或者:

SELECT INVENTORY.product, INVENTORY.version, PRODUCTS.customer
FROM INVENTORY
INNER JOIN PRODUCTS ON
INVENTORY.product = PRODUCTS.product AND INVENTORY.version= PRODUCTS.version
GROUP BY INVENTORY.product, INVENTORY.version, PRODUCTS.customer