You are here:

MS SQL/To get duplicate entries on same date

Advertisement


Question
I need to retreive rows including duplicate rows that fall between two dates.
for example if there are many rows and i need to find all rows including duplicate rows that fall between some start date and end date

Answer
Hi Bhavesh, It will be best if you can share table details including data and expected results.

You can use group by with having to do that.

SELECT DateColumn, COUNT(1) AS RowCount
FROM TableName
WHERE DateColumn BETWEEN 'StartDate' and 'EndDate'
GROUP BY DateColumn
HAVING COUNT(1) > 1

Above query will give you dates where you have more than 1 record for the given date and that date falls between start and end date.

There are other ways of doing this as well but this is simple, especially when I don't have much details about your requirement.

If you simply need all the records including duplicate one then just use this simple query

SELECT *
FROM TableName
WHERE DateColumn BETWEEN 'StartDate' and 'EndDate'


Regards
Mohit

MS SQL

All Answers


Answers by Expert:


Ask Experts

Volunteer


Mohit Nayyar

Expertise

Microsoft SQL Server: T-SQL development (stored procedures, triggers, functions), Database optimization, performance tuning, high availability (Clustering, Log Shipping, Mirroring, Replication), scalability, SQL Server migration (Sybase/Oracle to SQL Server), SSIS/DTS, Data Warehousing (Kimball Methodology), ETL (SSIS), Cube (SSAS), Reporting Services (SSRS), database modeling, database administration, Security implementation and typically anything related to Microsoft SQL Server.

Experience

With over 10 years of experience in Database Administration, Development, Business Intelligence solutions and managing enterprise level database solutions based on Microsoft SQL Server.
Publications
IT Magazine: ASP, SQL

Publications
IT Magazine: ASP, SQL
SQLServerCentral.com

Education/Credentials
MCA (Masters)

Awards and Honors
Brainbench Certified: RDBMS
MCTS: DBA/Developer/BI for SQL Server 2005/SQL Server 2008
MCITP: DBA/Developer/BI for SQL Server 2005/SQL Server 2008
MCDBA: SQL Server 2000
MCP: SQL Server 6.5

©2016 About.com. All rights reserved.