I have one table with two columns:
StartDateTime
EndDateTime
What will be best query to find out which rows has same (StartDateTime, EndDateTime)?
McNets
24k11 gold badges51 silver badges90 bronze badges
asked Jan 3, 2019 at 21:17
1 Answer 1
You did not specify a particular RDBMS (SQL Server, Oracle, etc.), but here is a quick solution that would probably work on most.
Assuming your table has some kind of unique key (primary key - like ID
) to determine the difference between one row and another row, you could use a correlated exists check.
SELECT a.*
FROM table1 a
WHERE EXISTS (
SELECT *
FROM table1
WHERE StartDateTime = a.StartDateTime
AND EndDateTime = a.EndDateTime
AND Id <> a.Id
)
answered Jan 3, 2019 at 21:56
lang-sql
postgresql
,oracle
,db2
,sql-server
, ...