1

I am using php to retrieve PostgreSQL data from a table, the data cannot be repeated, I already have a way of getting data without repeated rows

SELECT DISTINCT realpath FROM paths WHERE fn='$fn'

what i need is a way of knowing which are the repeated rows

1 Answer 1

2
with a as (
  SELECT count(1),realpath 
  FROM paths WHERE fn='$fn'
  GROUP BY realpath 
)
select realpath 
from a
where count > 1

updtae As Abelisto suggested, my attempt to make it more clear using CTE might fail, so shorter and better way:

  SELECT count(1),realpath 
  FROM paths WHERE fn='$fn'
  GROUP BY realpath 
  HAVING count(1) > 1
Sign up to request clarification or add additional context in comments.

2 Comments

Why not just use having count(*) > 1?
dunno. just thought it will be clearer to OP. of course having is shorter... I'll probably edit to have both, you are right

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.