Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check for duplicate record in postgresql

Tags:

sql

postgresql

I have one table in postgresql and my table contain one column of timestamp without timezone

i want to write one query which will check if same date inserted multiple times or not if same date present more than once query should return that date

like 12 Sep 2011,12 Sep 2011,12 Sep 2011,10 Sep 2011,

Here 12 Sep 2011 date is present more than once how to write query for that

like image 978
jai prakash Avatar asked May 13 '26 21:05

jai prakash


2 Answers

SELECT my_date FROM my_table GROUP BY my_date HAVING COUNT(my_date) > 1
like image 111
reader_1000 Avatar answered May 15 '26 11:05

reader_1000


If you have timestamps, you should drop the 'time' part:

SELECT time_column::DATE FROM my_table GROUP BY time_column::DATE HAVING COUNT(*) > 1
like image 39
Marco Mariani Avatar answered May 15 '26 10:05

Marco Mariani



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!