Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Duplicate values Re-Posted

Status
Not open for further replies.

rez3366

Programmer
Aug 19, 2004
2
US
Please ignore the previous post as it is not correct.
I have a table with the following structure :

NGP NPA ZIP Dfault

"AAR" "734" "48104" ""
"ABA" "256" "35951" ""
"ABC" "626" "91770" ""
"ABL" "325" "79607" ""
"ABL" "915" "79607" ""
"ABN" "253" "98003" ""
"ABY" "541" "97321" ""
"ACA" "256" "35010" ""
"ACC" "805" "93422" ""
"ACT" "978" "02119" ""
"ADR" "517" "49221" ""
"AFW" "682" "76012" ""
"AFW" "817" "76014 " "Y"
"AGA" "229" "31707" ""
"AGC" "805" "93420" ""
"AHC" "224" "60005 " "Y"
"AHI" "847" "60005" "Y"
"AHD", "888" "60005" ""

I need to extract unique values based on the third column
NGP. So for example there are 3 instances of "6005" and I need to have only one of those pulled from the table.
A distinct statement will not work.
Many thanks in advance.
 
Since it does not matter which record to pick of those with the same NGP, you may select the one with maximum value of NPA.
Code:
select 
  a.NGP
, a.NPA
, (select ZIP from table where NGP=a.NGP and NPA=a.NPA and Dfault='Y') ZIP
from
(select distinct NGP,max(NPA) NPA from table where Dfault='Y' group by NGP) a
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top