Query to find all records with either same value or null value [message #648549] |
Thu, 25 February 2016 04:16 ![Go to next message Go to next message](/forum/theme/orafaq/images/down.png) |
![](http://www.gravatar.com/avatar/11f67423f65459cc345b1d5a50c06336?s=64&d=mm&r=g) |
ranugupta3
Messages: 2 Registered: February 2016
|
Junior Member |
|
|
I Need to find all records from a table of zip code having zip_code, City and Country code
Now my requirement is to find all records with same zip_code . At the same time the City of These zip_codes can be either all same or null.
my sample data is
zip_code zip_city
1234 abc
1234 abc
1234 null
1567 def
1567 fgh
3456 efg
3456 efg
Output desired :
zip_code zip_city
1234 abc
|
|
|
|
Re: Query to find all records with either same value or null value [message #648553 is a reply to message #648551] |
Thu, 25 February 2016 05:59 ![Go to previous message Go to previous message](/forum/theme/orafaq/images/up.png) ![Go to next message Go to next message](/forum/theme/orafaq/images/down.png) |
![](http://www.gravatar.com/avatar/11f67423f65459cc345b1d5a50c06336?s=64&d=mm&r=g) |
ranugupta3
Messages: 2 Registered: February 2016
|
Junior Member |
|
|
My Problem : it gives records with same zip_code and zip_city also. I want only those records with same code and City either same or null. But in one record it has to be null.
For example in my sample data above. my code Piece with return "3456 efg" also but thats not my requirement.
Below is my code Piece :
SELECT zz.zip_zip
,zz.zip_city
,zz.id_seq_zip
FROM tzip zz
WHERE zz.zip_zip IN (SELECT a.zip_zip
FROM (SELECT z.zip_zip
,z.zip_city
,COUNT(z.zip_zip)
FROM tzip z
GROUP BY z.zip_zip
,z.zip_city
HAVING(COUNT(*) > 1)) a)
ORDER BY 1
[Updated on: Thu, 25 February 2016 06:00] Report message to a moderator
|
|
|
|
|
|