Results 1 to 2 of 2
Thread: Comparing Columns In Posgre SQL
01-25-13, 18:19 #1Registered User
- Join Date
- Jan 2013
Comparing Columns In Posgre SQL
I am trying to weed out bad data in a Address table. I have an instance where
Column Address3 imported City, state, and zip and Column Zip also imported the zip code in random cases. I need to get rid of the zip code in these random cases. I want to run a comparison of Address3 and Zip to see where Address3 is LIKE Zip or vise versa so I can isolate the data. For example:
Column Address 3
Watertown, NY 15674
What would be a query that would compare these? Thanks! X)
01-27-13, 19:29 #2Registered User
- Join Date
- Dec 2012
Do you want to compare the five last characters from column "Address3" with column "ZIP" and you want all lines where these a different?
Assuming that column "ZIP" is a text or varchar column.
In the examlpe below you have to replace "Your_Table_Name" with the right table name of course.
SELECT Address3,ZIP FROM Your_Table_Name WHERE substr(Address3,length(Address3)-4,5) <> ZIP;
PostgreSQL: Documentation: 9.1: String Functions and Operators