• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 38
  • Last Modified:

SQL: Find duplicate by date

Hi

I have a PostGreSQL/PostGIS database
Something like this

ID, Group_ code , point_number, date, geom
1, 1234, 1 , 2018-05-10, geom
2, 1234, 2 , 2018-05-10, geom
3, 1234, 3 , 2018-05-10, geom
4, 1234, 4 , 2018-05-10, geom
5, 1234, 5 , 2018-05-10, geom
6, 1235, 1 , 2017-05-10, geom
7, 1235, 2 , 2017-05-10, geom
8, 1235, 3 , 2017-05-10, geom
9, 1235, 4 , 2017-05-10, geom
10, 1234, 1 , 2017-05-10, geom  // WRONG

Open in new window


I can have multiple Group_ code  the same but the should have the same date

I need to find all rows where the same Group_ code has 2 or more dates
0
trevor1940
Asked:
trevor1940
  • 2
2 Solutions
 
SujithData ArchitectCommented:
select group_code
from <table>
group by group_code
having count(distinct date) > 1
0
 
HuaMin ChenSystem AnalystCommented:
Hi,
One other note is, to please avoid using "date" as the column, as it is reserved word in other databases, like Oracle and SQL SERVER.
0
 
trevor1940Author Commented:
Thanx your query worked

BTW actual date column called date_time
0
 
SujithData ArchitectCommented:
You are welcome
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Improve Your Query Performance Tuning

In this FREE six-day email course, you'll learn from Janis Griffin, Database Performance Evangelist. She'll teach 12 steps that you can use to optimize your queries as much as possible and see measurable results in your work. Get started today!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now