Ismail
Ismail

Reputation: 644

SQL query, am I wrong somewhere?

I am trying to pull distinct City names and only one zipcode for any given City.

zip city    state
00603   AGUADILLA   PR
00604   AGUADILLA   PR
00605   AGUADILLA   PR

Query:

SELECT DISTINCT (city),(zip) 
  FROM zips 
 WHERE state = 'PR'

I tried group by clause as well, let me know where am I wrong here.

Upvotes: 0

Views: 54

Answers (2)

GolezTrol
GolezTrol

Reputation: 116100

SELECT city, max(zip) from zips where state='PR' group by city, state

Upvotes: 1

Blindy
Blindy

Reputation: 67382

select city, max(zip)
from zips
where state='PR'
group by city

Upvotes: 2

Related Questions