0

I combine 3 tables. But there are lines that repeat in single tablature. I want to show them as a single line.

SELECT
  COUNT(gelenhaberlerimage.HaberKodu) AS Expr1,
  gelenhaberaciklama.id,
  gelenhaberaciklama.HaberKodu,
  gelenhaberler.id AS Expr2,
  gelenhaberler.HaberKodu AS Expr3,
  gelenhaberler.Sehir,
  gelenhaberler.title,
  gelenhaberlerimage.id AS Expr4,
  gelenhaberlerimage.HaberKodu AS Expr5,
  gelenhaberlerimage.BuyukResim
FROM
  gelenhaberaciklama 
INNER JOIN
  gelenhaberler ON gelenhaberaciklama.HaberKodu = gelenhaberler.HaberKodu 
INNER JOIN
  gelenhaberlerimage ON gelenhaberaciklama.HaberKodu = gelenhaberlerimage.HaberKodu 
GROUP BY
  gelenhaberaciklama.id,
  gelenhaberaciklama.HaberKodu,
  gelenhaberler.id,
  gelenhaberler.HaberKodu,
  gelenhaberler.Sehir,
  gelenhaberler.title,
  gelenhaberlerimage.id,
  gelenhaberlerimage.HaberKodu,
  gelenhaberlerimage.BuyukResim 
HAVING
  (COUNT(gelenhaberlerimage.HaberKodu) > 1)
fabis
  • 3
  • 7
  • 1
    could you perhaps reframe the question with a simplified example? obviously we dn't know which of your tables / columns here are the duplicated ones; a fake example with 2 tables each with max 3 columns and some dummy data - plus your intended results - would make it **much** clearer what you're asking – Marc Gravell Jul 19 '18 at 08:51
  • You can try to use DISTINCT, like this "SELECT DISTINCT ..." – Fábio Nascimento Jul 19 '18 at 08:55
  • 1
    Just as a fun fact: you can actually use a UNION to deduplicate data. So SELECT ColA, ColB, ColC FROM TableA UNION SELECT ColA, ColB, ColC FROM TableA results in distinct values. – SQL_M Jul 19 '18 at 09:02
  • SELECT DISTINCT not inner join? – fabis Jul 19 '18 at 09:03

1 Answers1

1

Use Distinct with Select statement to avoid repeating records. Here is a link which might help SQL SELECT DISTINCT Statement

Tabby
  • 91
  • 1
  • 1
  • 10