Skip to content
Advertisement

SQL join two tables by modifying on columns

I have 3 tables on PostgreSQL:

SPENDINGS:

STORE:

CUSTOMER:

I would love to join these tables like this:

How can I do that could you help me out please?

Advertisement

Answer

trim(store.zip_code) is not good for the job because the whitespace is within the zip code text. Use replace(store.zip_code, ' ', '') instead. right(spendings.store, 6) does not seem safe to me too. Better use ltrim(spendings.store, '0') to remove leading zeroes. SQL Fiddle

BTW your data design does need improvement.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement