I have a table with the following structure
[id] [int] IDENTITY(1,1) NOT NULL,
[account_number] [int] NOT NULL,
[account_name] [varchar(100)] NULL,
[account_chapter] [varchar(20)] NULL,
There can be many rows with the same account_number, but differents account_name and account_chapters.
For example, we can have something like the following :
id account_number account_name account_chapter
12 1111 Name01 chapter01
13 1111 Name02 chapter02
14 2222 Name03 chapter07
15 2222 Name05 chapter11
16 7777 Name06 chapter44
What i want is a query that for each account_number, filter only the first occurence in the table. For example, the query above must be transformed in the following :
id account_number account_name account_chapter
12 1111 Name01 chapter01
14 2222 Name03 chapter07
16 7777 Name06 chapter44
Here is the query i wrote :
with req01 as (select distinct account_number from accounts)
select * from req01 full join (select * from accounts) as p on p.account_number = req01.account_number
It do not produce the expected result.
Any help ? Thanks.