简体   繁体   中英

SQL: find distinct values for only few columns

I have a table that looks like below:

ID    Address1       City   State    Zip      YearBuilt 
1    704 Grant Ave    X        Y     11111      2000
2    704 Grant Ave    X        Y     11111      2000
3    704 Grant Ave    X        Y     11111      2000
4    303 2nd St       A        B     22222      1900
5    303 2nd St       A        B     22222      1900
6    44 North ST      C        D     33333      1950

Now I want to have only those rows which have distinct Address1, City, State, and Zip . ID cannot be used as an identifier because for same address it has a different ID. I'm okay to keep the top ID.

SELECT MIN(ID), Address1, City, State, Zip FROM ... GROUP BY Address1, City, State, Zip

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