sql - Selecting TOP 1 Columns where duplicate exists and selecting all where no duplicate exists -


given list of names, accounts , positions trying to:

  1. select 1st position there more 1 records same name , account
  2. 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

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -