MySQL: Selecting One Record When Others Have Same Data
Posted
by LoganFrederick
on Stack Overflow
See other posts from Stack Overflow
or by LoganFrederick
Published on 2009-07-08T16:22:46Z
Indexed on
2010/03/09
6:06 UTC
Read the original article
Hit count: 186
mysql
I have a table of cities that all share the same area code:
367 01451 Harvard Worcester Massachusetts MA 978 Eastern
368 01452 Hubbardston Worcester Massachusetts MA 978 Eastern
369 01453 Leominster Worcester Massachusetts MA 978 Eastern
The table has multiple area codes, all with multiple cities.
What I'd like to do is only select one city from each area code and delete any extra cities from duplicate area codes. What would be the best query to accomplish this?
I believe: http://stackoverflow.com/questions/596629/mysql4-sql-for-selecting-one-or-zero-record
Is coming close to what I need but didn't quite get what/how those answers were working.
Note The "978" row is the "area_code" row, table name is "zip_code".
© Stack Overflow or respective owner