sql - Selecting TOP 1 Columns where duplicate exists and selecting all where no duplicate exists -
given list of names, accounts , positions trying to:
- select 1st position there more 1 records same name , account
- if there 1 record name , account, select details.
my current query looks following:
select * cte cte1 join ( select name, oppname cte group name, oppname having count(name)>1 ) cte2 on cte2.name = cte1.name , cte2.oppname = cte1.oppname order cte1.oppname, cte1.name
i have not posted rest of cte query way long. however, providing me results name , accounts same , positions different.
i.e. if oera worked @ christie's sales analyst , developer select record oera worked @ christie's developer.
how modify query accordingly?
are looking this?
select * cte cte1 join ( select name, oppname,count(name) partition (name,oppname) cnt cte ) cte2 on cte2.name = cte1.name , cte2.oppname = cte1.oppname cnt > 1 order cte1.oppname, cte1.name
Comments
Post a Comment