In below Table the Primary Key is: Id, ClientId, CertificateId. The column AccountId is duplicated because AccountId may have different client and clients may have different certificates. Below script for table and data to manipulate.
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[TableB](
[Id] [int] NOT NULL,
[ClientId] [int] NOT NULL,
[CertificateId] [int] NOT NULL,
[AccountId] [int] NOT NULL,
[Status] [bit] NULL,
CONSTRAINT [PK_TableB] PRIMARY KEY CLUSTERED
(
[Id] ASC,
[ClientId] ASC,
[CertificateId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
INSERT [dbo].[TableB] ([Id], [ClientId], [CertificateId], [AccountId], [Status]) VALUES (1, 5, 34, 1, 1)
INSERT [dbo].[TableB] ([Id], [ClientId], [CertificateId], [AccountId], [Status]) VALUES (2, 8, 34, 1, 1)
INSERT [dbo].[TableB] ([Id], [ClientId], [CertificateId], [AccountId], [Status]) VALUES (3, 7, 36, 2, 1)
INSERT [dbo].[TableB] ([Id], [ClientId], [CertificateId], [AccountId], [Status]) VALUES (4, 9, 37, 3, 1)
INSERT [dbo].[TableB] ([Id], [ClientId], [CertificateId], [AccountId], [Status]) VALUES (5, 10, 35, 4, 1)
INSERT [dbo].[TableB] ([Id], [ClientId], [CertificateId], [AccountId], [Status]) VALUES (6, 4, 37, 4, 0)
INSERT [dbo].[TableB] ([Id], [ClientId], [CertificateId], [AccountId], [Status]) VALUES (7, 61, 34, 4, 1)
INSERT [dbo].[TableB] ([Id], [ClientId], [CertificateId], [AccountId], [Status]) VALUES (8, 45, 35, 5, 1)
GO
When I execute this query: SELECT * FROM TableB WHERE [Status]=1
I get the following results
Id | ClientId | CertificateId | AccountId | Status
1 | 5 | 34 | 1 | 1
2 | 8 | 34 | 1 | 1
3 | 7 | 36 | 2 | 1
4 | 9 | 37 | 3 | 1
5 | 10 | 35 | 4 | 1
7 | 61 | 34 | 4 | 1
8 | 45 | 35 | 5 | 1
Please help me to get below result, means if any AccountId is repeated then select top 1 and output should like this
Id | ClientId | CertificateId | AccountId | Status
1 | 5 | 34 | 1 | 1
3 | 7 | 36 | 2 | 1
4 | 9 | 37 | 3 | 1
5 | 10 | 35 | 4 | 1
8 | 45 | 35 | 5 | 1