2014-06-04 2 views
0

나는 내 쿼리 결과에서 모든 중복을 제거하기 위해 여러 가지를 시도했지만 그 중 아무 것도 작동하지 않았습니다. 나는 DISTINCTGROUP BY을 시도했다.SQL은 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; 

난 당신이 ROW_NUMBER 함수를 사용하여 정렬 categories.Try this.I`m을 사용하여 정렬하려고하는 것을 볼 수 있습니까 그리고 당신이 SQL 서버를 사용하고 있다고 가정하면

+0

Access 데이터베이스를 사용하고 있는데 Access에서도 작동합니까? – user3708994

+0

그걸로 잘 모르겠다. 어쨌든 한번 해봐. –

+0

작동하지 않는 것 같아요. – user3708994

관련 문제