2014-06-11 1 views
-1
select DISTINCT IDDetail, NamaProperti, Provinsi, Kota, Area, TipeListing, JenisProperti, Hadapnya, JenisSertifikat, Harga, LT, LB, foto1 from MsProperti as mp, MsSertifikat as ms, MsDetail as md, MsTipeListing mt where md.IDProperti = mp.IDProperti and md.IDSertifikat = ms.IDSertifikat and md.IDTipeListing = mt.IDTipeListing and Provinsi = 'BSD' or Kota = 'BSD' or Area = 'BSD' and AlreadySold = 0 order by IDDetail desc 

별다른 차이가 없다면 같은 데이터를 많이 줘야한다는 것을 알고있다. 그런 다음 Select를 선택하면 DISTINCT를 넣어서 동일한 데이터 만 제공한다. 그러나 그것은 전혀 다르지 않습니다.이 Distinct SQL 쿼리를 어떻게 해결할 것인가

아무 것도 제안하지 않습니까?

그리고 대답은 WHERE 쿼리 종료 후에 GROUP BY를 추가하는 것입니다. 이것은 asnwer

select IDDetail, NamaProperti, Provinsi, Kota, Area, TipeListing, JenisProperti, Hadapnya, JenisSertifikat, Harga, LT, LB, foto1 
from MsProperti as mp, MsSertifikat as ms, MsDetail as md, MsTipeListing mt 
where md.IDProperti = mp.IDProperti and 
md.IDSertifikat = ms.IDSertifikat and 
md.IDTipeListing = mt.IDTipeListing ".$tambahquery." and AlreadySold = 0 
group by IDDetail 
order by IDDetail desc 

감사합니다.

+1

이'그룹을 시도 by' 대신' – Jens

+0

를 distinct'하지만 –

+0

해결, 감사 청바지를 설명처럼이 쿼리 반환의 모든 데이터가 동일합니다. –

답변

0

DISTINCT 대신 GROUP BY을 사용하십시오. 마찬가지로 :

SELECT 
    IDDetail, 
    NamaProperti, 
    Provinsi, 
    Kota, 
    Area, 
    TipeListing, 
    JenisProperti, 
    Hadapnya, 
    JenisSertifikat, 
    Harga, 
    LT, 
    LB, 
    foto1 
FROM 
    MsProperti as mp, 
    MsSertifikat as ms, 
    MsDetail as md, 
    MsTipeListing mt 
WHERE 
    md.IDProperti = mp.IDProperti AND 
    md.IDSertifikat = ms.IDSertifikat AND 
    md.IDTipeListing = mt.IDTipeListing AND 
    Provinsi = 'BSD' OR 
    Kota = 'BSD' OR 
    Area = 'BSD' AND 
    AlreadySold = 0 
GROUP BY 
    IDDetail, 
    NamaProperti, 
    Provinsi, 
    Kota, 
    Area, 
    TipeListing, 
    JenisProperti, 
    Hadapnya, 
    JenisSertifikat, 
    Harga, 
    LT, 
    LB, 
    foto1 
ORDER BY 
    IDDetail DESC 
관련 문제