I have one table with two columns:


What will be best query to find out which rows has same (StartDateTime, EndDateTime)?

  • Please consider reading this post
    – mustaccio
    Commented Jan 4, 2019 at 1:58
  • Which DBMS product are you using? "SQL" is just a query language, not the name of a specific database product (a table in a relational database is always a "SQL table"). Please add the tag for the database product you are using postgresql, oracle, db2, sql-server, ...
    – user1822
    Commented Jan 5, 2019 at 10:23

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.

FROM table1 a
        SELECT *
        FROM table1
        WHERE StartDateTime = a.StartDateTime
            AND EndDateTime = a.EndDateTime
            AND Id <> a.Id

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.