2011-05-16 3 views
0

J'essaie de tirer des noms distincts City et un seul code postal pour une ville donnée.Requête SQL, ai-je tort quelque part?

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

Requête:

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

j'ai essayé groupe par article et, permettez-moi de savoir où je me trompe ici.

Répondre

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

GMTA, non? :) – GolezTrol

+0

en effet, frère. – Blindy

+0

Merci @ Blindy et Golez. Ça marche. – Ismail

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