Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Remove duplicates with in 10 min
--Sql Server 2014 Express Edition --Batches are separated by 'go' create Table Datetimetable ( ID int, Name varchar(30) , DateTime1 datetime ) Insert into Datetimetable(ID,Name,DateTime1)values(1,'Joe','2017-03-01 11:33:13'); Insert into Datetimetable(ID,Name,DateTime1)values(1,'Joe','2017-03-01 11:33:14'); Insert into Datetimetable(ID,Name,DateTime1)values(1,'Joe','2017-03-01 11:33:15'); Insert into Datetimetable(ID,Name,DateTime1)values(1,'Joe','2017-03-01 11:55:30'); Insert into Datetimetable(ID,Name,DateTime1)values(1,'John','2017-03-15 08:55:48'); Insert into Datetimetable(ID,Name,DateTime1)values(1,'John','2017-03-15 08:55:49'); Insert into Datetimetable(ID,Name,DateTime1)values(1,'John','2017-03-15 10:15:40'); with cte as ( select *,row_number() over( partition by ( CAST(CONVERT(CHAR(16), [DateTime1],113) AS datetime)) order by [Name]) as rn from Datetimetable ) select * from cte where rn=1 select *, row_number() over ( partition by (CAST(convert(CHAR(16),DateTime1,113)AS datetime)) order by Name) from Datetimetable SELECT A.ID,A.NAME,A.[DATETIME1] FROM (SELECT *,ROW_NUMBER() OVER( PARTITION BY ( CAST(CONVERT(CHAR(16), [DATETIME1],113) AS DATETIME)) ORDER BY [NAME]) AS RN FROM Datetimetable )A WHERE RN=1 ORDER BY ID
run
|
edit
|
history
|
help
2
code
Record rows
The relational division
Stackoverflow 37635278
Many-to-Many Join Example
Microsoft SQL Server T-SQL in 10mn ~ Lesson 15. Creating Advanced Joins samples...
archu
self join
Demo
BRYAN_BD