Avatar of bendecko
bendecko

asked on 

select distinct on one field only

Hi I'd like to do a DISTINCT query but just on one Field.

E.g.

zip              City               State              Area

10001      NEW YORK      New York      EMPIRE STATE
10001      NEW YORK      New York      G P O
10001      NEW YORK      New York      GREELEY SQUARE
10001      NEW YORK      New York      MACYS FINANCE
10001      NEW YORK      New York      MANHATTAN
10001      NEW YORK      New York      NEW YORK
10001      NEW YORK      New York      NEW YORK CITY
10001      NEW YORK      New York      NY
10001      NEW YORK      New York      NY CITY
10001      NEW YORK      New York      NYC
10002      NEW YORK      New York      KNICKERBOCKER
10002      NEW YORK      New York      MANHATTAN
10002      NEW YORK      New York      NEW YORK
10002      NEW YORK      New York      NYC

When I do a SELECT DISTINCT on here.. I get all rows.

Whereas what I want is to get each zip code out and then the distinct extra columns?
Microsoft SQL Server

Avatar of undefined
Last Comment
bendecko
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of twobitbela
twobitbela

You could do a
SELECT zip, area FROM zipTable GROUP BY zip, area
Avatar of bendecko
bendecko

ASKER

Thanks!

How could I do it via a temporary table?

Bendecko
>How could I do it via a temporary table?

what do you want to achieve using a temp table?
Avatar of bendecko
bendecko

ASKER

Dont worry it was just the performance was real slow.  I figured a temp table would 'guide' the execution order somewhat... In the end I just removed a LIKE clause which was the reason for the delay.

Thanks again!

Bendecko
Microsoft SQL Server
Microsoft SQL Server

Microsoft SQL Server is a suite of relational database management system (RDBMS) products providing multi-user database access functionality.SQL Server is available in multiple versions, typically identified by release year, and versions are subdivided into editions to distinguish between product functionality. Component services include integration (SSIS), reporting (SSRS), analysis (SSAS), data quality, master data, T-SQL and performance tuning.

171K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo