2014-06-04 264 views
0

我已经尝试了多种方法来摆脱查询结果中的所有重复项,但都无效。我试过DISTINCTGROUP BYSQL删除INNER JOIN中的重复项

DISTINCT不会做任何事情,GROUP BY我不断收到错误。

我的查询:提前

SELECT   
    categorie.categorie_id AS categorie, 
    categorie.categorie_nummer, 
    categorie.naam, 
    product.product_id, product.product_naam, 
    foto.foto_id, foto.foto1, 
    item.prijs, item.item_id 
FROM    
    ((((((categorie 
INNER JOIN 
    behoort_tot ON categorie.categorie_id = behoort_tot.categorie_id) 
INNER JOIN 
    product ON behoort_tot.product_id = product.product_id) 
INNER JOIN 
    heeft ON product.product_id = heeft.product_id) 
INNER JOIN 
    foto ON heeft.foto_id = foto.foto_id) 
INNER JOIN 
    is_een_1 ON product.product_id = is_een_1.product_id) 
INNER JOIN 
    item ON is_een_1.item_id = item.item_id) 
WHERE   
    (categorie.categorie_id = ?) 

感谢

+1

单独'DISTINCT'应该工作。 – woot

+1

你可以添加你正在得到的结果吗?如果没有'DISTINCT'子句? – brazilianldsjaguar

+0

感谢您的快速反应,我想上传我的结果图像,但它不会让我下10代表。但是输出完全相同,有或没有DISTINCT – user3708994

回答

0
WITH TEMP AS 
     (

    SELECT categorie.categorie_id AS categorie, categorie.categorie_nummer, categorie.naam, 
    product.product_id, product.product_naam, foto.foto_id, foto.foto1, item.prijs, item.item_id, 
    ROW_NUMBER() 
     OVER (PARTITION BY categorie.categorie_id ORDER BY categorie.categorie_id) As ROW_NO 


FROM   ((((((categorie INNER JOIN 
         behoort_tot ON categorie.categorie_id = behoort_tot.categorie_id) 
INNER JOIN 
         product ON behoort_tot.product_id = product.product_id) INNER JOIN 
         heeft ON product.product_id = heeft.product_id) INNER JOIN 
         foto ON heeft.foto_id = foto.foto_id) INNER JOIN 
         is_een_1 ON product.product_id = is_een_1.product_id) INNER JOIN 
         item ON is_een_1.item_id = item.item_id) 

) 
SELECT * FROM TEMP WHERE ROW_NO = 1; 

我看到你试图理清使用categories.Try this.I`m使用ROW_NUMBER函数分类整理并假设你正在使用SQL服务器

+0

我正在使用Access数据库,它在Access中也能工作吗? – user3708994

+0

我不敢确定。反正试一试 –

+0

似乎不起作用 – user3708994