I am looking to do a join from a column that has values with multiple digits (4 or 5 digits numbers) with another column also with digits (2,3,4,5 digits). The join should only be done on the 5 digit numbers.
Input Post_full Post_new 23 11 2345 23 23456 234 34567 2345 23456 Output 23456 (As this is the only 5 digit value in the input on both sides)
Advertisement
Answer
Use the length()
function in the WHERE
clause:
select t1.Post_full from table1 t1 inner join table2 t2 on t1.Post_full = t2.Post_new where length(t1.Post_full) = 5 and length(t2.Post_new) = 5