0

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
2
  • Please consider reading this post 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, ... Commented Jan 5, 2019 at 10:23

1 Answer 1

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

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.