简体   繁体   中英

Query to group similar columns values based on different other column value

I would like to get the information about the legal names which has different system originator and ID. So, can anyone help me with the query?

My Query is :

 SELECT ID,
    SystemOriginator,
    LegalName
FROM Institution
ORDER BY LegalName,
    SystemOriginator

Test Data:

   ID    SystemOriginator   LegalName  
 ------ ------------------ ----------- 
  2382   MLA                FC STONE   
  2382   MLA                FC STONE   
  2171   MLA                XYZ        
  2871   New System         XYZ        
  2171   MLA                XYZ        

and the result I want to achieve is :

   ID    SystemOriginator   LegalName  
 ------ ------------------ ----------- 
  2382   MLA                FC STONE   
  2171   MLA                XYZ        
  2871   New System         XYZ        
select distinct ID,
                SystemOriginator,
                LegalName
from Institution
ORDER BY LegalName, SystemOriginator

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM