We have a table that lists png images and their source URL's.
Sometimes the table has rows with the same image URL's but different image pixel widths and heights. I want to remove such duplicates, keeping only the duplicate that has the biggest image width then biggest image height.
I've tried various methods that I used to use in MSAccess (like GroupBy and First but First for example isn't available in SQL Server so thought I'd ask for T-SQL help).
Can anyone give T-SQL that would remove the duplicates (keeping the biggest image row of each duplicate)?
CREATE TABLE [dbo].[tblImageSuggestions]
(
[CounterID] [bigint] IDENTITY(700996,1) NOT NULL,
[CreatedDateTime] [datetime] NOT NULL,
[EmailAddress] [nvarchar](200) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[ImageOriginalURL] [nvarchar](2000) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[ImageOriginalWidthPixels] [int] NOT NULL,
[ImageOriginalHeightPixels] [int] NOT NULL,
CONSTRAINT [PK_tblImageSuggestions]
PRIMARY KEY CLUSTERED ([CounterID] ASC)
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF,
IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON,
ALLOW_PAGE_LOCKS = ON)
)
SET IDENTITY_INSERT [dbo].[tblImageSuggestions] ON
INSERT [dbo].[tblImageSuggestions] ([CounterID], [CreatedDateTime], [EmailAddress], [ImageOriginalURL], [ImageOriginalWidthPixels], [ImageOriginalHeightPixels])
VALUES (701030, CAST(0x0000A6AD0005543F AS DateTime), N'[email protected]', N'MyURL1', 1024, 1024)
INSERT [dbo].[tblImageSuggestions] ([CounterID], [CreatedDateTime], [EmailAddress], [ImageOriginalURL], [ImageOriginalWidthPixels], [ImageOriginalHeightPixels])
VALUES (701031, CAST(0x0000A6AD00055445 AS DateTime), N'[email protected]', N'MyURL2', 450, 450)
INSERT [dbo].[tblImageSuggestions] ([CounterID], [CreatedDateTime], [EmailAddress], [ImageOriginalURL], [ImageOriginalWidthPixels], [ImageOriginalHeightPixels])
VALUES (701032, CAST(0x0000A6AD00055489 AS DateTime), N'[email protected]', N'MyURL3', 3000, 3000)
INSERT [dbo].[tblImageSuggestions] ([CounterID], [CreatedDateTime], [EmailAddress], [ImageOriginalURL], [ImageOriginalWidthPixels], [ImageOriginalHeightPixels])
VALUES (701033, CAST(0x0000A6AD00055768 AS DateTime), N'[email protected]', N'MyURL2', 1024, 1024)
INSERT [dbo].[tblImageSuggestions] ([CounterID], [CreatedDateTime], [EmailAddress], [ImageOriginalURL], [ImageOriginalWidthPixels], [ImageOriginalHeightPixels])
VALUES (701034, CAST(0x0000A6AD00055771 AS DateTime), N'[email protected]', N'MyURL1', 450, 450)
INSERT [dbo].[tblImageSuggestions] ([CounterID], [CreatedDateTime], [EmailAddress], [ImageOriginalURL], [ImageOriginalWidthPixels], [ImageOriginalHeightPixels])
VALUES (701035, CAST(0x0000A6AD0005577A AS DateTime), N'[email protected]', N'MyURL4', 768, 768)
SET IDENTITY_INSERT [dbo].[tblImageSuggestions] OFF